package com.fsbm.ctech.maxis.ebpsbackend;

//import com.fsbm.ctech.controller.*;
import com.checkfree.isolutions.admin.ObjectId;

import java.awt.Color;
import java.io.*;
import java.util.*;
import java.text.*;

import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPageEvent;
import com.lowagie.text.pdf.PdfPageEventHelper;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.ExceptionConverter;
import com.lowagie.text.FontFactory;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Chunk;
import com.lowagie.text.Font;
import com.lowagie.text.Phrase;
import com.lowagie.text.Element;
import com.lowagie.text.Image;
import com.lowagie.text.Rectangle;
import com.lowagie.text.PageSize;

import com.checkfree.isolutions.persist.PersistServer;
import com.checkfree.isolutions.statement.*;
import com.checkfree.isolutions.statement.persist.*;
import com.checkfree.isolutions.streaming.IClassId;
import com.checkfree.isolutions.utility.CFiError;


public class PDFServlet_v4r00 extends PdfPageEventHelper{

    boolean isAccSumm=false;
    String currAccSummSection="";
    String accSummAccName="";
    String accSummStmtDate="";
    //PdfPTable summTable;

    public static String ACC_SUMM_LINE_DETAILS="Line Details";
    public static String ACC_SUMM_OTHER_CHARGES="Other Charges";
    public static String ACC_SUMM_DISC_REBATES="Discount & Rebates";
    public static String ACC_SUMM_SERVICE_TAX="Service Tax (6%)";
    public static String ACC_SUMM_TALKTIME_SUMM="Talktime Summary";

    // for account summary table rows calculation purpose;
    int rowsPerPage = 80;
    int rowCount =0;


	/**
	 * Constructor
	 */
    public PDFServlet_v4r00() {

        try {


        } catch (Exception e) {
            System.err.println(e.getMessage());
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        String strStmtId="";

        for ( int i = 0; i < args.length; i++ ) {
            if (args[i].toLowerCase().indexOf("-stmtid") !=-1)
            {
                String buffer = args[i];
                int pos = buffer.indexOf("=");
                strStmtId = buffer.substring(pos+1);
                continue;
            }
        }

        // Execute program
        PDFServlet_v4r00 pdf = new PDFServlet_v4r00();
        //pdf.StatementGeneration(strStmtId);

        // GSM
        pdf.StatementGeneration("17001", "D:/tmp/17001.pdf"); //header problem
        pdf.StatementGeneration("18001", "D:/tmp/18001.pdf"); //line problem
        pdf.StatementGeneration("6001", "D:/tmp/6001.pdf");
        pdf.StatementGeneration("7001", "D:/tmp/7001.pdf");
        pdf.StatementGeneration("9001", "D:/tmp/9001.pdf");
        pdf.StatementGeneration("10001", "D:/tmp/10001.pdf");
        // ISP
        pdf.StatementGeneration("8001", "D:/tmp/8001.pdf"); //**
        pdf.StatementGeneration("11001", "D:/tmp/11001.pdf");

        //MFNB
        pdf.StatementGeneration("12001", "D:/tmp/12001.pdf");
        pdf.StatementGeneration("13001", "D:/tmp/13001.pdf"); //**

        //MFNH
        pdf.StatementGeneration("14001", "D:/tmp/14001.pdf");

    }
/**
 * Generate the statement for the given statement id and output file name
 * @param strStmtId
 * @param pdfFileName
 */
    public void StatementGeneration(String strStmtId,String pdfFileName) {
        try {

        	//PersistServer.activate("Maxis");
        	//PersistServer.beginTransaction();

            StatementHome home = StatementHomeImpl.singleton();
            int statementId = Integer.parseInt(strStmtId);

            ObjectId objectId = new ObjectId(IClassId.STATEMENT, statementId);
            Statement cfiStatement   = home.findByObjectId(objectId);

           	//Get section from root section
           	final StatementSection cfiRootSection = cfiStatement.getRootSection();
		   	final StatementSection cfiSummarySection = cfiRootSection.getSection("SummarySection");
		   	final StatementSection cfiBillingPeriodSection = cfiRootSection.getSection("BillingPeriodSection");
			final StatementSection cfiDepositPaidSection = cfiRootSection.getSection("DepositPaidSection");
			final StatementSection cfiCreditLimitSection = cfiRootSection.getSection("CreditLimitSection");
			final StatementSection cfiImportantMessagesSection = cfiRootSection.getSection("ImportantMessagesSection");
			final StatementSection cfiCurrentPromotionSection = cfiRootSection.getSection("CurrentPromotionSection");

			//Get data field from root section
			final String AccNo = EbppxUtil.htmlEncode(cfiRootSection.getFieldText("AccountNumber"));
			final String StmtDt = EbppxUtil.htmlEncode(cfiRootSection.getFieldText("StatementDate"));
			final String AccName = EbppxUtil.htmlEncode(cfiRootSection.getFieldText("AccountName"));
		  	final String TotalAmountDue = EbppxUtil.htmlEncode(cfiRootSection.getFieldText("TotalAmountDue"));

			// Added by Meau for rounding
		  	String TotalAmount = EbppxUtil.htmlEncode(cfiRootSection.getFieldText("TotalAmount"));

			// end added by Meau for rounding

		  	final String PhoneNo = EbppxUtil.htmlEncode(cfiRootSection.getFieldText("PhoneNumber"));
		  	final String RefNo = EbppxUtil.htmlEncode(cfiRootSection.getFieldText("ReferenceNumber"));
		  	final String CurrentChargesDueDate = EbppxUtil.htmlEncode(cfiRootSection.getFieldText("CurrentChargesDueDate"));
		  	final String Address1 = EbppxUtil.htmlEncode(cfiRootSection.getFieldText("Address1"));
		  	final String Address2 = EbppxUtil.htmlEncode(cfiRootSection.getFieldText("Address2"));
		  	final String Address3 = EbppxUtil.htmlEncode(cfiRootSection.getFieldText("Address3"));
		  	final String Address4 = EbppxUtil.htmlEncode(cfiRootSection.getFieldText("Address4"));
		  	final String MarketSegment = EbppxUtil.htmlEncode(cfiRootSection.getFieldText("MarketSegment"));
		  	final String OldAccountNumber = EbppxUtil.htmlEncode(cfiRootSection.getFieldText("OldAccountNumber"));

		  	//Get data field from billing period section
		  	String BillPeriod = "";
		  	if(cfiBillingPeriodSection!=null){
				BillPeriod = EbppxUtil.htmlEncode(cfiBillingPeriodSection.getFieldText("BillingPeriod"));
			}

		  	//Get data field from deposit paid section
		  	String DepositPaid = "";
		  	if(cfiDepositPaidSection!=null){
				DepositPaid = EbppxUtil.htmlEncode(cfiDepositPaidSection.getFieldText("DepositPaid"));
			}

		  	//Get data field from credit limit section
		  	String CreditLimit = "";
		  	if(cfiCreditLimitSection!=null){
				CreditLimit = EbppxUtil.htmlEncode(cfiCreditLimitSection.getFieldText("CreditLimit"));
			}

		  	//Get data field from Summary section
		  	final String PreviousBalance = EbppxUtil.htmlEncode(cfiSummarySection.getFieldText("PreviousBalance"));
		  	final String PaymentReceived = EbppxUtil.htmlEncode(cfiSummarySection.getFieldText("PaymentReceived"));
		  	final String Adjustment = EbppxUtil.htmlEncode(cfiSummarySection.getFieldText("Adjustments"));
		  	final String OverdueCharges = EbppxUtil.htmlEncode(cfiSummarySection.getFieldText("OverdueCharges"));
		  	final String CurrentCharges = EbppxUtil.htmlEncode(cfiSummarySection.getFieldText("CurrentCharges"));
		  	final String PaymentDueDate = EbppxUtil.htmlEncode(cfiSummarySection.getFieldText("CurrentChargesDueDate"));


			String[] MessageLine = new String[23];

			if(cfiImportantMessagesSection!=null){
				//Get data field from important messages section
			    for (int i=1; i < 23; i++) {
			        MessageLine[i] = EbppxUtil.htmlEncode(cfiImportantMessagesSection.getFieldText("MessageLine"+i));
			    }
			}

			//Padding Amount
			int tpPadBottom = 8;
			int tpPadTop = 3;
			int tpPadRight = 8;
			int tpPadLeft = 8;

			final Date dtVal = cfiStatement.getDate();
            final DateFormat dfdisp = new SimpleDateFormat("ddMMMyyyy");
            String stdate = EbppxUtil.htmlEncode(dfdisp.format(dtVal));

            String filename = new String(strStmtId+"-"+stdate);
           	filename += ".pdf";

           	String OutPath = "D://";

		    //	ServletResponse response;
			//response.setContentType("application/pdf");
		   	//response.setHeader("Content-Disposition","attachment; filename=" + filename);

           	Document document = new Document(PageSize.A4, 40, 40, 40, 80); //Pagesize, left, right, top, bottom margin
           	//Document document = new Document();

	   		PdfWriter writer = null;

	   	    writer = PdfWriter.getInstance(document, new FileOutputStream(pdfFileName));

	   		// this will activate the method OnOpenDocument(), OnCloseDocument() and OnEndPage()
            writer.setPageEvent(this);

	   		document.open();

				//Write data to PDF

                //Crate Main Table for page position purpose
                float[] tableColsWidth = {4f, 2f};
                PdfPTable table = new PdfPTable(tableColsWidth);

                //set the table width percentage of the page
                table.setWidthPercentage(100);

				//Declare
				Chunk chunk;
				Phrase phrase;
				Paragraph paragraph;
				PdfPCell cell;
				Font font = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL,new Color(0, 0, 0));
				Font fontItalic = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.ITALIC,new Color(0, 0, 0));
				Font fontBold = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.BOLD,new Color(0, 0, 0));
				Font fontSpace = FontFactory.getFont(FontFactory.HELVETICA, 10, Font.NORMAL,new Color(0, 0, 0));
				Font bigFontItalic = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.ITALIC,new Color(0, 0, 0));
				Font bigFontBold = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD,new Color(0, 0, 0));

				//Title
				phrase = new Phrase();
				chunk = new Chunk("STATEMENT OF ACCOUNT\n", bigFontBold);
				phrase.add(chunk);
				chunk = new Chunk("PENYATA AKAUN", bigFontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
				cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
				cell.setColspan(2);
				cell.setBorderWidth(0);
				table.addCell(cell);

				//Account Name
				phrase = new Phrase();
				chunk = new Chunk("Account Name / ", fontBold);
				phrase.add(chunk);
				chunk = new Chunk("Nama Akaun : ", fontItalic);
				phrase.add(chunk);
				chunk = new Chunk(AccName, fontBold);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setColspan(2);
				cell.setBorderWidth(0);
				table.addCell(cell);

				//Add blank row
				cell = new PdfPCell(new Phrase("",fontBold));
				cell.setColspan(2);
				cell.setBorderWidth(0);
				table.addCell(cell);

				//Crate sub Table inside main table
                float[] subTableColsWidth = {4.2f, 4.0f, 0.9f, 3.2f, 0.3f, 4.1f};
                PdfPTable subTable = new PdfPTable(subTableColsWidth);

				//sub table header1
				phrase = new Phrase();
				chunk = new Chunk("Previous Balance\n", fontBold);
				phrase.add(chunk);
				chunk = new Chunk("Baki Dahulu ", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_CENTER);
				subTable.addCell(cell);

				//sub table header2-3
				phrase = new Phrase();
				chunk = new Chunk("Payment Received\n", fontBold);
				phrase.add(chunk);
				chunk = new Chunk("Jumlah Bayaran Diterima ", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setColspan(2);
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
				subTable.addCell(cell);

				//sub table header4
				phrase = new Phrase();
				chunk = new Chunk("Adjustments\n", fontBold);
				phrase.add(chunk);
				chunk = new Chunk("Penyelarasan ", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_CENTER);
				subTable.addCell(cell);

				//sub table header5-6 - empty
				phrase = new Phrase();
				chunk=new Chunk("");
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setColspan(2);
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
				cell.setBorderWidth(0);
				subTable.addCell(cell);

/////////////////////////
				//sub table Previous Balance [col 1]
				phrase = new Phrase();
				chunk = new Chunk(PreviousBalance, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_CENTER);
				cell.setPaddingTop(tpPadTop);
				cell.setPaddingBottom(tpPadBottom);
				subTable.addCell(cell);

				//sub table Payment Received [col 2-3]
				phrase = new Phrase();
				chunk = new Chunk(PaymentReceived, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
                cell.setColspan(2);
				cell.setHorizontalAlignment(Element.ALIGN_CENTER);
				cell.setPaddingTop(tpPadTop);
				cell.setPaddingBottom(tpPadBottom);
				subTable.addCell(cell);

				//sub table Adjustment [col 4]
				phrase = new Phrase();
				chunk = new Chunk(Adjustment, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_CENTER);
				cell.setPaddingTop(tpPadTop);
				cell.setPaddingBottom(tpPadBottom);
				subTable.addCell(cell);

				//sub table empty [col 5-6]
				phrase = new Phrase();
				chunk = new Chunk("", font);
				cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_CENTER);
				cell.setPaddingTop(tpPadTop);
				cell.setPaddingBottom(tpPadBottom);
				cell.setColspan(2);
				cell.setBorderWidth(0);
				subTable.addCell(cell);

				//add big blank row at sub table
				cell = new PdfPCell(new Phrase("",font));
				cell.setBorderWidth(0);
				cell.setColspan(6);
				cell.setPaddingTop(tpPadTop);
				cell.setPaddingBottom(tpPadBottom);
				subTable.addCell(cell);

///////////////////////////////
				//Overdue charges Title at sub table [col 1-2]
				phrase = new Phrase();
				chunk = new Chunk("Overdue Charges\n", fontBold);
				phrase.add(chunk);
				chunk = new Chunk("Caj Tertunggak", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
                cell.setColspan(2);
                cell.setBorderWidth(0);
				cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
				subTable.addCell(cell);

				//Overdue charges Content at sub table [col 3-4]
				phrase = new Phrase();
				chunk = new Chunk(OverdueCharges, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
                cell.setColspan(2);
				cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
				cell.setPaddingTop(tpPadTop);
				cell.setPaddingBottom(tpPadBottom);
				cell.setPaddingRight(tpPadRight);
				subTable.addCell(cell);

				// Blank cell [col 5]
				phrase = new Phrase();
				chunk = new Chunk("");
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
                cell.setBorderWidth(0);
				subTable.addCell(cell);

				// Payment Due Date Title at sub table [col 6]
				phrase = new Phrase();
				chunk = new Chunk("Payment Due Date\n", fontBold);
				phrase.add(chunk);
				chunk = new Chunk("Tarikh Akhir Bayaran", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_CENTER);
				subTable.addCell(cell);

				//add blank row at sub table
				cell = new PdfPCell(new Phrase("",fontSpace));
				cell.setBorderWidth(0);
				cell.setColspan(6);
				subTable.addCell(cell);

////////////////////////////////
				//Current charges Title at sub table [col 1-2]
				phrase = new Phrase();
				chunk = new Chunk("Current Charges\n", fontBold);
				phrase.add(chunk);
				chunk = new Chunk("Caj Semasa", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
                cell.setColspan(2);
                cell.setBorderWidth(0);
				cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
				subTable.addCell(cell);

				//Current charges Content at sub table [col 3-4]
				phrase = new Phrase();
				chunk = new Chunk(CurrentCharges, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
                cell.setColspan(2);
				cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
				cell.setPaddingTop(tpPadTop);
				cell.setPaddingBottom(tpPadBottom);
				cell.setPaddingRight(tpPadRight);
				subTable.addCell(cell);

				// Blank cell [col 5]
				phrase = new Phrase();
				chunk = new Chunk("");
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
                cell.setBorderWidth(0);
				subTable.addCell(cell);

				//Payment Due Date Content at sub table [col 6]
				phrase = new Phrase();
				chunk = new Chunk(PaymentDueDate, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_CENTER);
				cell.setPaddingTop(tpPadTop);
				cell.setPaddingBottom(tpPadBottom);
				cell.setPaddingRight(tpPadRight);
				subTable.addCell(cell);

				//add blank row at sub table
				cell = new PdfPCell(new Phrase("",fontSpace));
				cell.setBorderWidth(0);
				cell.setColspan(6);
				subTable.addCell(cell);

/////////////////////////////
/////////////////// Added by Meau for rounding/////////////////////////////////////////
				if(TotalAmount!=null && !TotalAmount.equals("")){
					//Total amount Title at sub table [col 1-2]
					phrase = new Phrase();
					chunk = new Chunk("Total amount \n", fontBold);
					phrase.add(chunk);
					chunk = new Chunk("Jumlah", fontItalic);
					phrase.add(chunk);
                	cell = new PdfPCell(phrase);
                	cell.setColspan(2);
                	cell.setBorderWidth(0);
					cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
					subTable.addCell(cell);

					//Total amount Content at sub table [col 3-4]
					phrase = new Phrase();
					chunk = new Chunk(TotalAmount, font);
					phrase.add(chunk);
                	cell = new PdfPCell(phrase);
                	cell.setColspan(2);
					cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
					cell.setPaddingTop(tpPadTop);
					cell.setPaddingBottom(tpPadBottom);
					cell.setPaddingRight(tpPadRight);
					subTable.addCell(cell);

					// Blank cell [col 5-6]
					phrase = new Phrase();
					chunk = new Chunk("");
					phrase.add(chunk);
	                cell = new PdfPCell(phrase);
	                cell.setColspan(2);
	                cell.setBorderWidth(0);
					subTable.addCell(cell);

					//add blank row at sub table
					cell = new PdfPCell(new Phrase("",fontSpace));
					cell.setBorderWidth(0);
					cell.setColspan(6);
					cell.setPaddingTop(tpPadTop);
					cell.setPaddingBottom(tpPadBottom);
					subTable.addCell(cell);
				}
///////////////////////////
				//Total amount due Title at sub table [col 1-2]
				phrase = new Phrase();
				chunk = new Chunk("Total amount due\n", fontBold);
				phrase.add(chunk);
				chunk = new Chunk("Jumlah Perlu Dibayar", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
                cell.setColspan(2);
                cell.setBorderWidth(0);
				cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
				subTable.addCell(cell);

				//Total amount due Content at sub table [col 3-4]
				phrase = new Phrase();
				chunk = new Chunk(TotalAmountDue, fontBold);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
                cell.setColspan(2);
				cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
				cell.setPaddingTop(tpPadTop);
				cell.setPaddingBottom(tpPadBottom);
				cell.setPaddingRight(tpPadRight);
				subTable.addCell(cell);

				// Blank cell [col 5-6]
				phrase = new Phrase();
				chunk = new Chunk("");
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
                cell.setColspan(2);
                cell.setBorderWidth(0);
				subTable.addCell(cell);

				for (int ii=0; ii < 3; ii++) {
					//add big blank row at sub table
					cell = new PdfPCell(new Phrase("",fontSpace));
					cell.setBorderWidth(0);
					cell.setColspan(6);
					cell.setPaddingTop(tpPadTop);
					cell.setPaddingBottom(tpPadBottom);
					subTable.addCell(cell);
				}

//////////////////////////////////////
				//Bill message
				phrase = new Phrase();
				chunk = new Chunk("Bill message / ", fontBold);
				phrase.add(chunk);
				chunk = new Chunk("Maklumat Bil:", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setColspan(6);
				cell.setBorder(PdfPCell.TOP);
				subTable.addCell(cell);

				//add blank row at sub table
				cell = new PdfPCell(new Phrase("",fontSpace));
				cell.setBorderWidth(0);
				cell.setColspan(6);
				subTable.addCell(cell);

				//Bill message row 1-22
				for (int i=1; i< 23; i++) {

				    if (MessageLine[i] !=null) {
						phrase = new Phrase();
						chunk = new Chunk(formatStr(MessageLine[i]), font);
						phrase.add(chunk);
		                cell = new PdfPCell(phrase);
						cell.setHorizontalAlignment(Element.ALIGN_LEFT);
						cell.setColspan(6);
						cell.setPaddingLeft(tpPadLeft);
						cell.setPaddingRight(tpPadRight);
						cell.setBorderWidth(0);
						subTable.addCell(cell);
				    }
				}


				//Add subTable
				cell = new PdfPCell(subTable);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorder(PdfPCell.RIGHT + PdfPCell.BOTTOM);
				cell.setPaddingRight(tpPadRight);
				cell.setPaddingTop(tpPadTop);
				cell.setPaddingBottom(tpPadBottom);
				table.addCell(cell);

				//Reuse sub Table inside main table second column
                float[] subTableColsWidth2 = {4f, 6f};
                subTable = new PdfPTable(subTableColsWidth2);

				//Account Number Title
				phrase = new Phrase();
				chunk = new Chunk("Account No.\n ", font);
				phrase.add(chunk);
				chunk = new Chunk("No.Akaun", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				cell.setPaddingLeft(tpPadLeft);
				subTable.addCell(cell);

				//Account Number content
				phrase = new Phrase();
				chunk = new Chunk(": " + AccNo + " (new) / " + OldAccountNumber, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				subTable.addCell(cell);

				//Reference No. Title
				phrase = new Phrase();
				chunk = new Chunk("Reference No.\n ", font);
				phrase.add(chunk);
				chunk = new Chunk("No.Rujukan", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				cell.setPaddingLeft(tpPadLeft);
				subTable.addCell(cell);

				//Reference No. content
				phrase = new Phrase();
				chunk = new Chunk(": " + RefNo, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				subTable.addCell(cell);

				//Statement Date Title
				phrase = new Phrase();
				chunk = new Chunk("Statement Date\n ", font);
				phrase.add(chunk);
				chunk = new Chunk("Tarikh Penyata", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				cell.setPaddingLeft(tpPadLeft);
				subTable.addCell(cell);

				//Statement Date content
				phrase = new Phrase();
				chunk = new Chunk(": " + StmtDt, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				subTable.addCell(cell);

				//Billing Period Title
				phrase = new Phrase();
				chunk = new Chunk("Billing Period\n ", font);
				phrase.add(chunk);
				chunk = new Chunk("Tempoh Bil", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				cell.setPaddingLeft(tpPadLeft);
				subTable.addCell(cell);

				//Billing Period content
				phrase = new Phrase();
				chunk = new Chunk(": " + BillPeriod, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				subTable.addCell(cell);

				//Deposit Paid Title
				phrase = new Phrase();
				chunk = new Chunk("Deposit Paid.\n ", font);
				phrase.add(chunk);
				chunk = new Chunk("Cagaran", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				cell.setPaddingLeft(tpPadLeft);
				subTable.addCell(cell);

				//Deposit Paid content
				phrase = new Phrase();
				chunk = new Chunk(": " + DepositPaid, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				subTable.addCell(cell);

				//Credit Limit Title
				phrase = new Phrase();
				chunk = new Chunk("Credit Limit\n ", font);
				phrase.add(chunk);
				chunk = new Chunk("Had Kredit", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				cell.setPaddingLeft(tpPadLeft);
				subTable.addCell(cell);

				//Credit Limit content
				phrase = new Phrase();
				chunk = new Chunk(": " + CreditLimit, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				subTable.addCell(cell);

				for (int ii=0; ii < 6; ii++) {
					//add big blank row at sub table
					cell = new PdfPCell(new Phrase("",fontBold));
					cell.setBorderWidth(0);
					cell.setColspan(2);
					cell.setPaddingTop(tpPadTop);
					cell.setPaddingBottom(tpPadBottom);
					subTable.addCell(cell);
				}


				//Add blank row
				cell = new PdfPCell(new Phrase("",fontBold));
				cell.setColspan(2);
				cell.setBorder(PdfPCell.BOTTOM);
				subTable.addCell(cell);

				//Current Promotion title
				phrase = new Phrase();
				chunk = new Chunk("Current Promotion / ", fontBold);
				phrase.add(chunk);
				chunk = new Chunk("Promosi Terkini:", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setColspan(2);
				cell.setBorderWidth(0);
				cell.setPaddingTop(tpPadTop);
				cell.setPaddingLeft(tpPadLeft);
				subTable.addCell(cell);

				//add big blank row at sub table
				cell = new PdfPCell(new Phrase("",fontSpace));
				cell.setBorderWidth(0);
				cell.setColspan(2);
				cell.setPaddingTop(tpPadTop);
				cell.setPaddingBottom(tpPadBottom);
				subTable.addCell(cell);

				//Current Promotion repeat section
				if(cfiCurrentPromotionSection!=null){
					StatementSection PromotionRepeatSection = null;
           			long DetailLines = cfiCurrentPromotionSection.getSectionCount("CurrentPromotionRepeatSection");

            		for (int i = 0; i < DetailLines; i++) {
            		    // Get the row section
            		    PromotionRepeatSection = cfiCurrentPromotionSection.getRepeatSection("CurrentPromotionRepeatSection", i);
  						//Column 3 : Name
	        	        cell = new PdfPCell(new Phrase(PromotionRepeatSection.getField("PromotionLine").asString(), font));
            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
            	    	cell.setPaddingLeft(tpPadLeft);
            	    	cell.setColspan(2);
            	    	cell.setBorderWidth(0);
            	    	subTable.addCell(cell);
					}//end For
				}
				//Add subTable
				cell = new PdfPCell(subTable);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorder(PdfPCell.BOTTOM);
				table.addCell(cell);

				//Footer
				//Message
				phrase = new Phrase();
				chunk = new Chunk("", font);
				phrase.add(chunk);
				chunk = new Chunk("", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				cell.setPaddingTop(tpPadTop);
				table.addCell(cell);

				//Payment Slip title
				phrase = new Phrase();
				chunk = new Chunk("PAYMENT SLIP\n", bigFontBold);
				phrase.add(chunk);
				chunk = new Chunk("SLIP BAYARAN", bigFontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
				cell.setBorderWidth(0);
				cell.setPaddingRight(tpPadRight);
				table.addCell(cell);

				//Create Table 2 inside main table to hold 2 sub table
                float[] TableColsWidth2 = {6f, 4f};
                PdfPTable table2 = new PdfPTable(TableColsWidth2);

				//Reuse sub Table inside main table fifth column
                float[] subTableColsWidth3 = { 4f, 6f};
                subTable = new PdfPTable(subTableColsWidth3);

                //Account Name title
				phrase = new Phrase();
				chunk = new Chunk("Account Name / ", font);
				phrase.add(chunk);
				chunk = new Chunk("Nama Akaun", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				subTable.addCell(cell);

				//Account Name content
				phrase = new Phrase();
				chunk = new Chunk(": " + AccName, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				subTable.addCell(cell);

                //Account no title
				phrase = new Phrase();
				chunk = new Chunk("Account No. / ", font);
				phrase.add(chunk);
				chunk = new Chunk("No. Akaun", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				subTable.addCell(cell);

				//Account no content
				phrase = new Phrase();
				chunk = new Chunk(": " + AccNo + " (new) / " + OldAccountNumber, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				subTable.addCell(cell);

                //phone no title
				phrase = new Phrase();
				chunk = new Chunk("Phone Number / ", font);
				phrase.add(chunk);
				chunk = new Chunk("No.Telefon", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				subTable.addCell(cell);

				//phone no content
				phrase = new Phrase();
				chunk = new Chunk(": " + PhoneNo, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				subTable.addCell(cell);

                //reference number title
				phrase = new Phrase();
				chunk = new Chunk("Reference Number / ", font);
				phrase.add(chunk);
				chunk = new Chunk("No. Rujukan", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				subTable.addCell(cell);

				//reference number content
				phrase = new Phrase();
				chunk = new Chunk(": " + RefNo, font);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				subTable.addCell(cell);

				//add big blank row at main table
				cell = new PdfPCell(new Phrase("",fontSpace));
				cell.setBorderWidth(0);
				cell.setColspan(2);
				cell.setPaddingTop(tpPadTop);
				cell.setPaddingBottom(tpPadBottom);
				table.addCell(cell);

				//add big blank row at main table
				cell = new PdfPCell(new Phrase("",fontSpace));
				cell.setBorderWidth(0);
				cell.setColspan(2);
				cell.setPaddingTop(tpPadTop);
				cell.setPaddingBottom(tpPadBottom);
				table.addCell(cell);

				//Add subTable
				cell = new PdfPCell(subTable);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				table2.addCell(cell);

				//Reuse sub Table inside main table sixth column
                float[] subTableColsWidth4 = {2f, 3f};
                subTable = new PdfPTable(subTableColsWidth4);

				//sub table Total Amount Due header
				phrase = new Phrase();
				chunk = new Chunk("Total Amount Due\n", fontBold);
				phrase.add(chunk);
				chunk = new Chunk("Jumlah Perlu Dibayar ", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_CENTER);
				cell.setGrayFill(0.8f);
				subTable.addCell(cell);

				//sub table header
				phrase = new Phrase();
				chunk = new Chunk("Current Charges Due Date\n", fontBold);
				phrase.add(chunk);
				chunk = new Chunk("Tarikh Akhir Bayaran Due Date ", fontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_CENTER);
				cell.setGrayFill(0.8f);
				subTable.addCell(cell);

				//sub table Total Amount Due value
				phrase = new Phrase();
				chunk = new Chunk(TotalAmountDue, fontBold);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_CENTER);
				cell.setPaddingTop(tpPadTop);
				cell.setPaddingBottom(tpPadBottom);
				subTable.addCell(cell);

				//sub table Current charges due date value
				phrase = new Phrase();
				chunk = new Chunk(PaymentDueDate, fontBold);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_CENTER);
				cell.setPaddingTop(tpPadTop);
				cell.setPaddingBottom(tpPadBottom);
				subTable.addCell(cell);

				//Add subTable
				cell = new PdfPCell(subTable);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				cell.setPaddingTop(12);
				table2.addCell(cell);

				//Add Table 2
				cell = new PdfPCell(table2);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setBorderWidth(0);
				cell.setColspan(2);
				table.addCell(cell);

				//add big blank row at main table
				cell = new PdfPCell(new Phrase("",fontSpace));
				cell.setBorderWidth(0);
				cell.setColspan(2);
				cell.setPaddingTop(tpPadTop);
				cell.setPaddingBottom(tpPadBottom);
				table.addCell(cell);

				//Account Name and Address
				phrase = new Phrase();
				chunk = new Chunk(AccName + "\n", fontBold);
				phrase.add(chunk);
				chunk = new Chunk(Address1 + "\n", fontBold);
				phrase.add(chunk);
				chunk = new Chunk(Address2 + "\n", fontBold);
				phrase.add(chunk);
				chunk = new Chunk(Address3 + "\n", fontBold);
				phrase.add(chunk);
				chunk = new Chunk(Address4 + "\n", fontBold);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setColspan(2);
				cell.setBorderWidth(0);
				cell.setPaddingLeft(50);
				table.addCell(cell);

				//blank column
                cell = new PdfPCell(new Phrase("", fontBold));
                cell.setBorderWidth(0);
				table.addCell(cell);

				//statement date
				phrase = new Phrase();
				chunk = new Chunk(StmtDt, fontBold);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setPaddingLeft(tpPadLeft);
				cell.setBorderWidth(0);
				table.addCell(cell);

		   	document.add(table);

			//Get Account Summary Section from root section
		   	final StatementSection cfiAccountSummarySection = cfiRootSection.getSection("AccountSummarySection");

		   	if(cfiAccountSummarySection!=null){
		   		document.newPage();

		   		addAccountSummarySec(writer, document, cfiAccountSummarySection, cfiRootSection);
		   	}

			// add the Details of Charges Section
		   	//Get Details Of Charges Section from root section
		   	final StatementSection cfiDetailsOfChargesSection = cfiRootSection.getSection("DetailsOfChargesSection");

		   	if(cfiDetailsOfChargesSection!=null){

		   		document.newPage();

		   		addDetailsOfChargesSec(writer, document, cfiDetailsOfChargesSection, cfiRootSection);
		   	}

			document.close();
			writer.flush();
            writer.close();

            //PersistServer.commitTransaction();

        } catch (Exception ex) {
            System.err.println("-- EXCEPTION: " + ex.getClass() + " "
                    + ex.getMessage());
            ex.printStackTrace();
        } catch (Throwable t) {
            System.err.println("-- EXCEPTION: " + t.getClass() + " " + t.getMessage());
            t.printStackTrace();
        }finally {
			//PersistServer.deactivate();
		}
    }

    /**
     * add the Account Summary to the table
     *
     * @param writer
     * @param document
     */
        public void addAccountSummarySec(PdfWriter writer, Document document, StatementSection cfiAccountSummarySection, StatementSection cfiRootSection) {

            // padding size for the cell
			int tpPadBottom = 5;
			int tpPadTop = 5;
			int tpPadRight = 5;
			int tpPadLeft = 5;

            try {

                // font used in this section
            	Font font = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL,new Color(0, 0, 0));
            	Font fontUnderline = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.UNDERLINE,new Color(0, 0, 0));
            	Font fontBig = FontFactory.getFont(FontFactory.HELVETICA, 9, Font.NORMAL,new Color(0, 0, 0));
				Font fontItalic = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.ITALIC,new Color(0, 0, 0));
				Font fontBold = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.BOLD,new Color(0, 0, 0));
				Font fontBigBold = FontFactory.getFont(FontFactory.HELVETICA, 9, Font.BOLD,new Color(0, 0, 0));
				Font fontSpace = FontFactory.getFont(FontFactory.HELVETICA, 10, Font.NORMAL,new Color(0, 0, 0));
				Font bigFontItalic = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.ITALIC,new Color(0, 0, 0));
				Font bigFontBold = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD,new Color(0, 0, 0));
				Color colorGrey = new Color (192, 192, 192);

                // Payment detail table column widths
                float headerwidths[] = { 7.7F, 2.3F, 4.0F, 2.0F }; // percentage
                PdfPTable transTable = new PdfPTable(headerwidths.length);
                transTable.setWidths(headerwidths);
                transTable.setWidthPercentage(100); // percentage

                // Account Summary Table
                float summTblwidths[] = { 5.3F, 2.6F, 2.6F, 3.0F, 2.7F, 2.5F, 3.6F, 3.1F};
                PdfPTable summTable = new PdfPTable(summTblwidths);
                summTable.setWidthPercentage(100);

                //Get data field from root section
    			final String AccNo = EbppxUtil.htmlEncode(cfiRootSection.getFieldText("AccountNumber"));
    			final String StmtDt = EbppxUtil.htmlEncode(cfiRootSection.getFieldText("StatementDate"));
    			final String AccName = EbppxUtil.htmlEncode(cfiRootSection.getFieldText("AccountName"));
    		  	final String TotalAmountDue = EbppxUtil.htmlEncode(cfiRootSection.getFieldText("TotalAmountDue"));

    		    // Set to global variable - for Account Summary table purpose in onStartPage() and onEndPage()
    		  	accSummAccName= AccName;
    		    accSummStmtDate= StmtDt;

    		    //Get account summary sections
    		   	final StatementSection cfiPaymentSection = cfiAccountSummarySection.getSection("PaymentSection");
    		   	final StatementSection cfiAdjustmentSection = cfiAccountSummarySection.getSection("AdjustmentSection");
    		   	final StatementSection cfiLineDetailsSection = cfiAccountSummarySection.getSection("LineDetailsSection");
    		   	final StatementSection cfiAccountDetailsSection = cfiAccountSummarySection.getSection("AccountDetailsSection");
    		   	final StatementSection cfiTotalCurrentChargesSection = cfiAccountSummarySection.getSection("TotalCurrentChargesSection");
    		   	final StatementSection cfiTalkTimeSummarySection = cfiAccountSummarySection.getSection("TalkTimeSummarySection");

    		   	// Page Height calculation purpose
    		   	//float bodyHeight = document.getPageSize().height() - document.topMargin() - document.bottomMargin();

                //Declaration
				Chunk chunk;
				Phrase phrase;
                PdfPCell cell = null;
                Image img = null;
                Paragraph newParagraph = null;

                //Title
				phrase = new Phrase();
				chunk = new Chunk("ACCOUNT SUMMARY\n", bigFontBold);
				phrase.add(chunk);
				chunk = new Chunk("RINGKASAN AKAUN", bigFontItalic);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
				cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
				cell.setColspan(4);
				cell.setBorderWidth(0);
				transTable.addCell(cell);

				//Add blank row
				cell = new PdfPCell(new Phrase("",fontBold));
				cell.setColspan(4);
				cell.setBorderWidth(0);
				transTable.addCell(cell);

				//Statement Date
				phrase = new Phrase();
				chunk = new Chunk("Statement Date / ", fontBold);
				phrase.add(chunk);
				chunk = new Chunk("Tarikh Penyata   ", fontItalic);
				phrase.add(chunk);
				chunk = new Chunk(":  " + StmtDt, fontBold);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setColspan(4);
				cell.setBorderWidth(0);
				transTable.addCell(cell);

				for (int line=0; line < 3; line++) {
					//Add blank row
					cell = new PdfPCell(new Phrase("",fontBold));
					cell.setColspan(4);
					cell.setBorderWidth(0);
					transTable.addCell(cell);
				}

				//Account Name
				phrase = new Phrase();
				chunk = new Chunk("Account Name / ", fontBold);
				phrase.add(chunk);
				chunk = new Chunk("Nama Akaun       ", fontItalic);
				phrase.add(chunk);
				chunk = new Chunk(":  " + AccName, fontBold);
				phrase.add(chunk);
                cell = new PdfPCell(phrase);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
				cell.setColspan(4);
				cell.setBorderWidth(0);
				transTable.addCell(cell);

				// Add 10 blank lines
				for (int i = 0; i < 10; i++) {
					cell = new PdfPCell(new Phrase("",fontBold));
					cell.setColspan(4);
					cell.setBorderWidth(0);
					transTable.addCell(cell);
				}

				rowCount+=13;


				//Payments section
				if(cfiPaymentSection!=null || cfiAdjustmentSection!=null){

					//Header 1
					//Column 1 Row 1 Header 1 - Item
					newParagraph = new Paragraph();
		            newParagraph.add(new Phrase("Item", fontBold));
		            cell = new PdfPCell(newParagraph);
		            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
		            cell.setBorder(PdfPCell.LEFT + PdfPCell.TOP);
		            cell.setPaddingLeft(tpPadLeft);
		            cell.setPaddingTop(tpPadTop);
		            cell.setGrayFill(0.8f);
		            transTable.addCell(cell);

		            //Column 2 Row 1 Header 1 - Date/Period
					newParagraph = new Paragraph();
		            newParagraph.add(new Phrase("Date/Period", fontBold));
		            cell = new PdfPCell(newParagraph);
		            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
		            cell.setBorder(PdfPCell.TOP);
		            cell.setPaddingTop(tpPadTop);
		            cell.setGrayFill(0.8f);
		            transTable.addCell(cell);

		            //Column 3 Row 1 Header 1 - Amount (RM)
					newParagraph = new Paragraph();
		            newParagraph.add(new Phrase("Amount (RM)", fontBold));
		            cell = new PdfPCell(newParagraph);
		            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
		            cell.setBorder(PdfPCell.TOP);
		            cell.setPaddingTop(tpPadTop);
		            cell.setGrayFill(0.8f);
		            transTable.addCell(cell);

		            //Column 4 Row 1 Header 1 - Total (RM)
					newParagraph = new Paragraph();
		            newParagraph.add(new Phrase("Total (RM)", fontBold));
		            cell = new PdfPCell(newParagraph);
		            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
		            cell.setBorder(PdfPCell.TOP + PdfPCell.RIGHT);
		            cell.setPaddingTop(tpPadTop);
		            cell.setPaddingRight(tpPadRight);
		            cell.setGrayFill(0.8f);
		            transTable.addCell(cell);

		            //Header 2
					//Column 1 Row 1 Header 2 - Item
					newParagraph = new Paragraph();
		            newParagraph.add(new Phrase("Item", fontItalic));
		            cell = new PdfPCell(newParagraph);
		            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
		            cell.setBorder(PdfPCell.LEFT + PdfPCell.BOTTOM);
		            cell.setPaddingBottom(tpPadBottom);
		            cell.setPaddingLeft(tpPadLeft);
		            cell.setGrayFill(0.8f);
		            transTable.addCell(cell);

		            //Column 2 Row 1 Header 2 - Tarikh/Tempoh
					newParagraph = new Paragraph();
		            newParagraph.add(new Phrase("Tarikh/Tempoh", fontItalic));
		            cell = new PdfPCell(newParagraph);
		            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
		            cell.setBorder(PdfPCell.BOTTOM);
		            cell.setPaddingBottom(tpPadBottom);
		            cell.setGrayFill(0.8f);
		            transTable.addCell(cell);

		            //Column 3 Row 1 Header 2 - Amaun (RM)
					newParagraph = new Paragraph();
		            newParagraph.add(new Phrase("Amaun (RM))", fontItalic));
		            cell = new PdfPCell(newParagraph);
		            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
		            cell.setBorder(PdfPCell.BOTTOM);
		            cell.setPaddingBottom(tpPadBottom);
		            cell.setGrayFill(0.8f);
		            transTable.addCell(cell);

		            //Column 4 Row 1 Header 2 - Jumlah (RM)
					newParagraph = new Paragraph();
		            newParagraph.add(new Phrase("Jumlah (RM)", fontItalic));
		            cell = new PdfPCell(newParagraph);
		            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
		            cell.setBorder(PdfPCell.BOTTOM + PdfPCell.RIGHT);
		            cell.setPaddingBottom(tpPadBottom);
		            cell.setPaddingRight(tpPadRight);
		            cell.setGrayFill(0.8f);
		            transTable.addCell(cell);

		            // SET THE HEADER ROWS
					transTable.setHeaderRows(19);

					rowCount+=3;

		            //Payments repeat section
					if(cfiPaymentSection!=null){

						//Payments Header
						newParagraph = new Paragraph();
			            newParagraph.add(new Phrase("Payment", fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
			            cell.setBorder(PdfPCell.BOTTOM);
			            cell.setPaddingBottom(tpPadBottom);
			            cell.setPaddingTop(tpPadTop);
			            cell.setPaddingLeft(tpPadLeft);
			            cell.setColspan(4);
			            transTable.addCell(cell);

			            rowCount+=2;

			            //Payments Repeat Section Part
						StatementSection PaymentsRepeatSection = null;
	           			long DetailLines = cfiPaymentSection.getSectionCount("RepeatSection");

	            		for (int i = 0; i < DetailLines; i++) {
	            		    // Get the row section
	            			PaymentsRepeatSection = cfiPaymentSection.getRepeatSection("RepeatSection", i);

	            			//Column 1 : Item
		        	        cell = new PdfPCell(new Phrase(PaymentsRepeatSection.getField("Item").asString(), font));
	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
	            	    	cell.setPaddingLeft(tpPadLeft);
	            	    	cell.setBorderWidth(0);
	            	    	transTable.addCell(cell);

	            	    	//Column 2 : Date
	            	    	if(PaymentsRepeatSection.getField("Date")!=null)
	            	    	{
	            	    		cell = new PdfPCell(new Phrase(PaymentsRepeatSection.getField("Date").asString(), font));
	            	    	}
	            	    	else
	            	    	{
	            	    		cell = new PdfPCell(new Phrase("", font));
	            	    	}
 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
 	            	    	cell.setBorderWidth(0);
 	            	    	transTable.addCell(cell);

	            	    	//Column 3 : Amount
 	            	    	if(PaymentsRepeatSection.getField("Amount")!=null)
	            	    	{
	            	    		cell = new PdfPCell(new Phrase(PaymentsRepeatSection.getField("Amount").asString(), font));
	            	    	}
	            	    	else
	            	    	{
	            	    		cell = new PdfPCell(new Phrase("", font));
	            	    	}
	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
	            	    	cell.setBorderWidth(0);
	            	    	cell.setPaddingRight(tpPadRight);
	            	    	transTable.addCell(cell);

	            	    	//Column 4 : Total
	            	    	if(PaymentsRepeatSection.getField("Total")!=null)
	            	    	{
			        	        cell = new PdfPCell(new Phrase(PaymentsRepeatSection.getField("Total").asString(), font));
	            	    	}
	            	    	else
	            	    	{
			        	        cell = new PdfPCell(new Phrase("", font));
	            	    	}
	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
	            	    	cell.setPaddingRight(tpPadRight);
	            	    	cell.setBorderWidth(0);
	            	    	transTable.addCell(cell);

						}//end For
	            		rowCount = rowCount + (int) (DetailLines*1.5);


	            		//Add a Blank Lines
	            		for (int ii=0; ii < 1; ii++) {
		            		cell = new PdfPCell(new Phrase("",fontBold));
	    					cell.setColspan(4);
	    					cell.setPaddingTop(tpPadTop);
	    					cell.setPaddingBottom(tpPadBottom);
	    					cell.setBorderWidth(0);
	    					transTable.addCell(cell);

	    					rowCount+=2;
	            		}
					}
		            //Adjustment repeat section
					if(cfiAdjustmentSection!=null){

						//Adjustment Header
						newParagraph = new Paragraph();
			            newParagraph.add(new Phrase("Adjustment", fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
			            cell.setBorder(PdfPCell.BOTTOM);
			            cell.setPaddingBottom(tpPadBottom);
			            cell.setPaddingTop(tpPadTop);
			            cell.setPaddingLeft(tpPadLeft);
			            cell.setColspan(4);
			            transTable.addCell(cell);

			            rowCount+=2;

			            //Adjustment Repeat Section Part
						StatementSection adjustmentRepeatSection = null;
	           			long DetailLines = cfiAdjustmentSection.getSectionCount("RepeatSection");

	            		for (int i = 0; i < DetailLines; i++) {
	            		    // Get the row section
	            			adjustmentRepeatSection = cfiAdjustmentSection.getRepeatSection("RepeatSection", i);

	            			//Column 1 : Item
		        	        cell = new PdfPCell(new Phrase(adjustmentRepeatSection.getField("Item").asString(), font));
	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
	            	    	cell.setPaddingLeft(tpPadLeft);
	            	    	cell.setBorderWidth(0);
	            	    	transTable.addCell(cell);

	            	    	//Column 2 : Date
	            	    	if(adjustmentRepeatSection.getField("Date")!=null)
	            	    	{
	            	    		cell = new PdfPCell(new Phrase(adjustmentRepeatSection.getField("Date").asString(), font));
	            	    	}
	            	    	else
	            	    	{
	            	    		cell = new PdfPCell(new Phrase("", font));
	            	    	}
 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
 	            	    	cell.setBorderWidth(0);
 	            	    	transTable.addCell(cell);

	            	    	//Column 3 : Amount
 	            	    	if(adjustmentRepeatSection.getField("Amount")!=null)
	            	    	{
	            	    		cell = new PdfPCell(new Phrase(adjustmentRepeatSection.getField("Amount").asString(), font));
	            	    	}
	            	    	else
	            	    	{
	            	    		cell = new PdfPCell(new Phrase("", font));
	            	    	}
	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
	            	    	cell.setBorderWidth(0);
	            	    	cell.setPaddingRight(tpPadRight);
	            	    	transTable.addCell(cell);

	            	    	//Column 4 : Total
	            	    	if(adjustmentRepeatSection.getField("Total")!=null)
	            	    	{
			        	        cell = new PdfPCell(new Phrase(adjustmentRepeatSection.getField("Total").asString(), font));
	            	    	}
	            	    	else
	            	    	{
			        	        cell = new PdfPCell(new Phrase("", font));
	            	    	}
	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
	            	    	cell.setPaddingRight(tpPadRight);
	            	    	cell.setBorderWidth(0);
	            	    	transTable.addCell(cell);

						}//end For

	            		rowCount = rowCount + (int) (DetailLines*1.5);

	            		//Add a Blank Lines
	            		for (int ii=0; ii < 1; ii++) {
		            		cell = new PdfPCell(new Phrase("",fontBold));
	    					cell.setColspan(4);
	    					cell.setPaddingTop(tpPadTop);
	    					cell.setPaddingBottom(tpPadBottom);
	    					cell.setBorderWidth(0);
	    					transTable.addCell(cell);

	    					rowCount+=2;
	            		}
					}
				}

				// add the table to the document
				document.add(transTable);

	//////////////// ACCOUNT SUMMARY TABLE //////////////////////////

				// for onStartPage() and onEndPage() event
				isAccSumm = true;

				//Header 1
				//Column 1 Row 1 Header 1 - Item
				newParagraph = new Paragraph();
	            newParagraph.add(new Phrase("Item", fontBold));
	            cell = new PdfPCell(newParagraph);
	            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
	            cell.setVerticalAlignment(PdfPCell.ALIGN_BOTTOM);
	            cell.setPaddingLeft(tpPadLeft);
	            cell.setPaddingBottom(tpPadBottom);
	            summTable.addCell(cell);

				//Column 2 Row 1 Header 1 - Monthly Charges
				newParagraph = new Paragraph();
	            newParagraph.add(new Phrase("Monthly\nCharges", fontBold));
	            cell = new PdfPCell(newParagraph);
	            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
	            cell.setVerticalAlignment(PdfPCell.ALIGN_BOTTOM);
	            cell.setPaddingLeft(tpPadLeft);
	            cell.setPaddingBottom(tpPadBottom);
	            summTable.addCell(cell);

				//Column 3 Row 1 Header 1 - Value Added Services
				newParagraph = new Paragraph();
	            newParagraph.add(new Phrase("Value\nAdded\nServices", fontBold));
	            cell = new PdfPCell(newParagraph);
	            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
	            cell.setVerticalAlignment(PdfPCell.ALIGN_BOTTOM);
	            cell.setPaddingLeft(tpPadLeft);
	            cell.setPaddingBottom(tpPadBottom);
	            summTable.addCell(cell);

				//Column 4 Row 1 Header 1 - Usage Charges
				newParagraph = new Paragraph();
	            newParagraph.add(new Phrase("Usage\nCharges", fontBold));
	            cell = new PdfPCell(newParagraph);
	            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
	            cell.setVerticalAlignment(PdfPCell.ALIGN_BOTTOM);
	            cell.setPaddingLeft(tpPadLeft);
	            cell.setPaddingBottom(tpPadBottom);
	            summTable.addCell(cell);

				//Column 5 Row 1 Header 1 - Other Charges
				newParagraph = new Paragraph();
	            newParagraph.add(new Phrase("Other\nCharges", fontBold));
	            cell = new PdfPCell(newParagraph);
	            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
	            cell.setVerticalAlignment(PdfPCell.ALIGN_BOTTOM);
	            cell.setPaddingLeft(tpPadLeft);
	            cell.setPaddingBottom(tpPadBottom);
	            summTable.addCell(cell);

				//Column 6 Row 1 Header 1 - Service ax
				newParagraph = new Paragraph();
	            newParagraph.add(new Phrase("Service\nTax", fontBold));
	            cell = new PdfPCell(newParagraph);
	            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
	            cell.setVerticalAlignment(PdfPCell.ALIGN_BOTTOM);
	            cell.setPaddingLeft(tpPadLeft);
	            cell.setPaddingBottom(tpPadBottom);
	            summTable.addCell(cell);

				//Column 7 Row 1 Header 1 - Discount & Rebates
				newParagraph = new Paragraph();
	            newParagraph.add(new Phrase("Discount &\nRebates", fontBold));
	            cell = new PdfPCell(newParagraph);
	            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
	            cell.setVerticalAlignment(PdfPCell.ALIGN_BOTTOM);
	            cell.setPaddingLeft(tpPadLeft);
	            cell.setPaddingBottom(tpPadBottom);
	            summTable.addCell(cell);

				//Column 8 Row 1 Header 1 - Total
				newParagraph = new Paragraph();
	            newParagraph.add(new Phrase("Total", fontBold));
	            cell = new PdfPCell(newParagraph);
	            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
	            cell.setVerticalAlignment(PdfPCell.ALIGN_BOTTOM);
	            cell.setPaddingLeft(tpPadLeft);
	            cell.setPaddingBottom(tpPadBottom);
	            summTable.addCell(cell);

	            rowCount+=3;

	            // set table headerRows
	            // summTable.setHeaderRows(2);
	            // summTable.setExtendLastRow(false);
	            // summTable.setKeepTogether(false);

///////LINE DETAILS
	            if (cfiLineDetailsSection !=null) {
	                // Line Details Header
	                currAccSummSection = ACC_SUMM_LINE_DETAILS;
	                newParagraph = new Paragraph();
		            newParagraph.add(new Phrase(ACC_SUMM_LINE_DETAILS, fontBold));
		            cell = new PdfPCell(newParagraph);
		            cell.setColspan(8);
		            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
		            cell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
		            cell.setPaddingTop(tpPadTop);
		            cell.setPaddingBottom(tpPadBottom);
		            cell.setPaddingLeft(tpPadLeft);
		            summTable.addCell(cell);

		            StatementSection cfiLineDetailsSubSection = cfiLineDetailsSection.getSection("LineDetailsSubSection");
		            SummaryRepeatSection srs = new SummaryRepeatSection(cfiLineDetailsSubSection);
		            int lineCount = (int) srs.getTotalRowCount();

		            for (int ii=0; ii < lineCount; ii++) {

		                //Item
		                String[] items = srs.getItem(ii);
			            newParagraph = new Paragraph();
			            for (int jj=0; jj < items.length; jj++) {
			                newParagraph.add(new Phrase(items[jj]+"\n", font));
			                rowCount++;
			            }
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
			            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
			            cell.setPaddingLeft(tpPadLeft);
			            summTable.addCell(cell);

			            // Monthly Charges
			            newParagraph = new Paragraph();
			            newParagraph.add(new Phrase(srs.getMonthlyCharges(ii), font));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
			            cell.setPaddingRight(tpPadRight);
			            summTable.addCell(cell);

			            // Value Added Services
			            newParagraph = new Paragraph();
			            newParagraph.add(new Phrase(srs.getVAS(ii), font));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
			            cell.setPaddingRight(tpPadRight);
			            summTable.addCell(cell);

			            // Usage Charges
			            newParagraph = new Paragraph();
			            newParagraph.add(new Phrase(srs.getUsageCharges(ii), font));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
			            cell.setPaddingRight(tpPadRight);
			            summTable.addCell(cell);

			            // Other Charges
			            newParagraph = new Paragraph();
			            newParagraph.add(new Phrase(srs.getOtherCharges(ii), font));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
			            cell.setPaddingRight(tpPadRight);
			            summTable.addCell(cell);

			            // Service Tax
			            newParagraph = new Paragraph();
			            newParagraph.add(new Phrase(srs.getServiceTax(ii), font));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
			            cell.setPaddingRight(tpPadRight);
			            summTable.addCell(cell);

			            // Discount & Rebates
			            newParagraph = new Paragraph();
			            newParagraph.add(new Phrase(srs.getDiscountRebates(ii), font));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
			            cell.setPaddingRight(tpPadRight);
			            summTable.addCell(cell);

			            // Total
			            newParagraph = new Paragraph();
			            newParagraph.add(new Phrase(srs.getTotal(ii), font));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
			            cell.setPaddingRight(tpPadRight);
			            summTable.addCell(cell);

			            // Blank Row
			            for (int k=0; k < 8; k++) {
				            newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("", font));
				            cell = new PdfPCell(newParagraph);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            summTable.addCell(cell);
			            }
			            rowCount++;

			            //check new page
			            if (rowCount > rowsPerPage) {
				            for (int k=0; k < 8; k++) {
					            newParagraph = new Paragraph();
					            newParagraph.add(new Phrase("", font));
					            cell = new PdfPCell(newParagraph);
					            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT + PdfPCell.BOTTOM);
					            summTable.addCell(cell);
				            }
				            //System.out.println("rowCount="+rowCount);

			                document.add(summTable);
			                summTable = new PdfPTable(summTblwidths);
			                summTable.setWidthPercentage(100);
			                document.newPage();

			            }

		            }

		            // Subtotal
		            StatementSection cfiLineTotalSection = cfiLineDetailsSection.getSection("LineTotalSection");
		            if (cfiLineTotalSection !=null) {
		                //Total Item
			            newParagraph = new Paragraph();
			            newParagraph.add(new Phrase("Subtotal", font));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
			            cell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
			            cell.setPaddingTop(tpPadTop);
			            cell.setPaddingBottom(tpPadBottom);
			            cell.setPaddingLeft(tpPadLeft);
			            rowCount++;
			            summTable.addCell(cell);

			            // Total Monthly Charges
			            newParagraph = new Paragraph();
			            newParagraph.add(new Phrase(cfiLineTotalSection.getFieldText("TotalMonthlyCharges"), fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            cell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
			            cell.setPaddingTop(tpPadTop);
			            cell.setPaddingBottom(tpPadBottom);
			            cell.setPaddingRight(tpPadRight);
			            summTable.addCell(cell);

			            // Total Value Added Services
			            newParagraph = new Paragraph();
			            newParagraph.add(new Phrase(cfiLineTotalSection.getFieldText("TotalVAS"), fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            cell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
			            cell.setPaddingTop(tpPadTop);
			            cell.setPaddingBottom(tpPadBottom);
			            cell.setPaddingRight(tpPadRight);
			            summTable.addCell(cell);

			            // Total Usage Charges
			            newParagraph = new Paragraph();
			            newParagraph.add(new Phrase(cfiLineTotalSection.getFieldText("TotalUsageCharges"), fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            cell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
			            cell.setPaddingTop(tpPadTop);
			            cell.setPaddingBottom(tpPadBottom);
			            cell.setPaddingRight(tpPadRight);
			            summTable.addCell(cell);

			            // Total Other Charges
			            newParagraph = new Paragraph();
			            newParagraph.add(new Phrase(cfiLineTotalSection.getFieldText("TotalOtherCharges"), fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            cell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
			            cell.setPaddingTop(tpPadTop);
			            cell.setPaddingBottom(tpPadBottom);
			            cell.setPaddingRight(tpPadRight);
			            summTable.addCell(cell);

			            // Total Service Tax
			            newParagraph = new Paragraph();
			            newParagraph.add(new Phrase(cfiLineTotalSection.getFieldText("TotalServiceTax"), fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            cell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
			            cell.setPaddingTop(tpPadTop);
			            cell.setPaddingBottom(tpPadBottom);
			            cell.setPaddingRight(tpPadRight);
			            summTable.addCell(cell);

			            // Total Discount & Rebates
			            newParagraph = new Paragraph();
			            newParagraph.add(new Phrase(cfiLineTotalSection.getFieldText("TotalDiscountRebates"), fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            cell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
			            cell.setPaddingTop(tpPadTop);
			            cell.setPaddingBottom(tpPadBottom);
			            cell.setPaddingRight(tpPadRight);
			            summTable.addCell(cell);

			            // Total Total
			            newParagraph = new Paragraph();
			            newParagraph.add(new Phrase(cfiLineTotalSection.getFieldText("TotalTotal"), fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            cell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
			            cell.setPaddingTop(tpPadTop);
			            cell.setPaddingBottom(tpPadBottom);
			            cell.setPaddingRight(tpPadRight);
			            summTable.addCell(cell);

			            rowCount++;
		            }
	            } // end if (cfiLineDetailsSection !=null)

/////////ACCOUNT DETAILS
				if (cfiAccountDetailsSection !=null) {
				    StatementSection cfiDiscountRebatesSection = cfiAccountDetailsSection.getSection("DiscountRebatesSection");
				    StatementSection cfiOtherChargesSection = cfiAccountDetailsSection.getSection("OtherChargesSection");
				    StatementSection cfiServiceTaxSection = cfiAccountDetailsSection.getSection("ServiceTaxSection");
				    StatementSection cfiAccountTotalSection = cfiAccountDetailsSection.getSection("AccountTotalSection");

	                // Account Details Header
	                newParagraph = new Paragraph();
		            newParagraph.add(new Phrase("Account Details", fontBold));
		            cell = new PdfPCell(newParagraph);
		            cell.setColspan(8);
		            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
		            cell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
		            cell.setPaddingTop(tpPadTop);
		            cell.setPaddingBottom(tpPadBottom);
		            cell.setPaddingLeft(tpPadLeft);
		            summTable.addCell(cell);
		            rowCount++;

				    if (cfiOtherChargesSection !=null) {
			            SummaryRepeatSection srs = new SummaryRepeatSection(cfiOtherChargesSection);
			            int lineCount = (int) srs.getTotalRowCount();

		                ///////////// Other Charges Header
		                // Column 1
			            currAccSummSection = ACC_SUMM_OTHER_CHARGES;
			            newParagraph = new Paragraph();
			            newParagraph.add(new Phrase(ACC_SUMM_OTHER_CHARGES, fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
			            cell.setPaddingLeft(tpPadLeft);
			            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
			            summTable.addCell(cell);
			            //Column 2
		                newParagraph = new Paragraph();
			            newParagraph.add(new Phrase("", fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            cell.setPaddingRight(tpPadRight);
			            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
			            summTable.addCell(cell);
			            //Column 3
		                newParagraph = new Paragraph();
			            newParagraph.add(new Phrase("", fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            cell.setPaddingRight(tpPadRight);
			            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
			            summTable.addCell(cell);
			            //Column 4
		                newParagraph = new Paragraph();
			            newParagraph.add(new Phrase("", fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            cell.setPaddingRight(tpPadRight);
			            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
			            summTable.addCell(cell);
			            //Column 5
		                newParagraph = new Paragraph();
			            newParagraph.add(new Phrase("", fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            cell.setPaddingRight(tpPadRight);
			            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
			            summTable.addCell(cell);
			            //Column 6
		                newParagraph = new Paragraph();
			            newParagraph.add(new Phrase("", fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            cell.setPaddingRight(tpPadRight);
			            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
			            summTable.addCell(cell);
			            //Column 7
		                newParagraph = new Paragraph();
			            newParagraph.add(new Phrase("", fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            cell.setPaddingRight(tpPadRight);
			            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
			            summTable.addCell(cell);
			            //Column 8
		                newParagraph = new Paragraph();
			            newParagraph.add(new Phrase("", fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            cell.setPaddingRight(tpPadRight);
			            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
			            summTable.addCell(cell);
			            rowCount++;
			            // Other Charges Repeat Data
			            for (int ii=0; ii < lineCount; ii++) {

				            // Blank Row
				            for (int k=0; k < 8; k++) {
					            newParagraph = new Paragraph();
					            newParagraph.add(new Phrase("", font));
					            cell = new PdfPCell(newParagraph);
					            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
					            summTable.addCell(cell);
				            }
				            rowCount++;
			                //Item
			                String[] items = srs.getItem(ii);
				            newParagraph = new Paragraph();
				            for (int jj=0; jj < items.length; jj++) {
				                newParagraph.add(new Phrase(items[jj]+"\n", font));
				                rowCount++;
				            }
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            cell.setPaddingLeft(tpPadLeft);
				            summTable.addCell(cell);

				            // Monthly Charges
				            newParagraph = new Paragraph();
				            newParagraph.add(new Phrase(srs.getMonthlyCharges(ii), font));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            cell.setPaddingRight(tpPadRight);
				            summTable.addCell(cell);

				            // Value Added Services
				            newParagraph = new Paragraph();
				            newParagraph.add(new Phrase(srs.getVAS(ii), font));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            cell.setPaddingRight(tpPadRight);
				            summTable.addCell(cell);

				            // Usage Charges
				            newParagraph = new Paragraph();
				            newParagraph.add(new Phrase(srs.getUsageCharges(ii), font));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            cell.setPaddingRight(tpPadRight);
				            summTable.addCell(cell);

				            // Other Charges
				            newParagraph = new Paragraph();
				            newParagraph.add(new Phrase(srs.getOtherCharges(ii), font));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            cell.setPaddingRight(tpPadRight);
				            summTable.addCell(cell);

				            // Service Tax
				            newParagraph = new Paragraph();
				            newParagraph.add(new Phrase(srs.getServiceTax(ii), font));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            cell.setPaddingRight(tpPadRight);
				            summTable.addCell(cell);

				            // Discount & Rebates
				            newParagraph = new Paragraph();
				            newParagraph.add(new Phrase(srs.getDiscountRebates(ii), font));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            cell.setPaddingRight(tpPadRight);
				            summTable.addCell(cell);

				            // Total
				            newParagraph = new Paragraph();
				            newParagraph.add(new Phrase(srs.getTotal(ii), font));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            cell.setPaddingRight(tpPadRight);
				            summTable.addCell(cell);

				            //check new page
				            if (rowCount > rowsPerPage) {
					            for (int k=0; k < 8; k++) {
						            newParagraph = new Paragraph();
						            newParagraph.add(new Phrase("", font));
						            cell = new PdfPCell(newParagraph);
						            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT + PdfPCell.BOTTOM);
						            summTable.addCell(cell);
					            }
					            //System.out.println("rowCount="+rowCount);
				                document.add(summTable);
				                summTable = new PdfPTable(summTblwidths);
				                summTable.setWidthPercentage(100);
				                document.newPage();
				            }


			            } //end for

			            // Blank Row
			            for (int k=0; k < 8; k++) {
				            newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("", font));
				            cell = new PdfPCell(newParagraph);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT + PdfPCell.BOTTOM);
				            summTable.addCell(cell);
			            }
			            rowCount++;

				    } //end if (cfiOtherChargesSection !=null)

				    if (cfiDiscountRebatesSection !=null) {
			            SummaryRepeatSection srs = new SummaryRepeatSection(cfiDiscountRebatesSection);
			            int lineCount = (int) srs.getTotalRowCount();

		                ///////////// Discount & Rebates Header
		                // Column 1
			            currAccSummSection = ACC_SUMM_DISC_REBATES;
			            newParagraph = new Paragraph();
			            newParagraph.add(new Phrase(ACC_SUMM_DISC_REBATES, fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
			            cell.setPaddingLeft(tpPadLeft);
			            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
			            summTable.addCell(cell);
			            //Column 2
		                newParagraph = new Paragraph();
			            newParagraph.add(new Phrase("", fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            cell.setPaddingRight(tpPadRight);
			            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
			            summTable.addCell(cell);
			            //Column 3
		                newParagraph = new Paragraph();
			            newParagraph.add(new Phrase("", fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            cell.setPaddingRight(tpPadRight);
			            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
			            summTable.addCell(cell);
			            //Column 4
		                newParagraph = new Paragraph();
			            newParagraph.add(new Phrase("", fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            cell.setPaddingRight(tpPadRight);
			            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
			            summTable.addCell(cell);
			            //Column 5
		                newParagraph = new Paragraph();
			            newParagraph.add(new Phrase("", fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            cell.setPaddingRight(tpPadRight);
			            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
			            summTable.addCell(cell);
			            //Column 6
		                newParagraph = new Paragraph();
			            newParagraph.add(new Phrase("", fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            cell.setPaddingRight(tpPadRight);
			            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
			            summTable.addCell(cell);
			            //Column 7
		                newParagraph = new Paragraph();
			            newParagraph.add(new Phrase("", fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            cell.setPaddingRight(tpPadRight);
			            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
			            summTable.addCell(cell);
			            //Column 8
		                newParagraph = new Paragraph();
			            newParagraph.add(new Phrase("", fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            cell.setPaddingRight(tpPadRight);
			            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
			            summTable.addCell(cell);
			            rowCount++;
			            // Discount & Rebates Repeat Data
			            for (int ii=0; ii < lineCount; ii++) {

				            // Blank Row
				            for (int k=0; k < 8; k++) {
					            newParagraph = new Paragraph();
					            newParagraph.add(new Phrase("", font));
					            cell = new PdfPCell(newParagraph);
					            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
					            summTable.addCell(cell);
				            }
				            rowCount++;
			                //Item
			                String[] items = srs.getItem(ii);
				            newParagraph = new Paragraph();
				            for (int jj=0; jj < items.length; jj++) {
				                newParagraph.add(new Phrase(items[jj]+"\n", font));
				                rowCount++;
				            }
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            cell.setPaddingLeft(tpPadLeft);
				            summTable.addCell(cell);

				            // Monthly Charges
				            newParagraph = new Paragraph();
				            newParagraph.add(new Phrase(srs.getMonthlyCharges(ii), font));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            cell.setPaddingRight(tpPadRight);
				            summTable.addCell(cell);

				            // Value Added Services
				            newParagraph = new Paragraph();
				            newParagraph.add(new Phrase(srs.getVAS(ii), font));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            cell.setPaddingRight(tpPadRight);
				            summTable.addCell(cell);

				            // Usage Charges
				            newParagraph = new Paragraph();
				            newParagraph.add(new Phrase(srs.getUsageCharges(ii), font));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            cell.setPaddingRight(tpPadRight);
				            summTable.addCell(cell);

				            // Other Charges
				            newParagraph = new Paragraph();
				            newParagraph.add(new Phrase(srs.getOtherCharges(ii), font));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            cell.setPaddingRight(tpPadRight);
				            summTable.addCell(cell);

				            // Service Tax
				            newParagraph = new Paragraph();
				            newParagraph.add(new Phrase(srs.getServiceTax(ii), font));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            cell.setPaddingRight(tpPadRight);
				            summTable.addCell(cell);

				            // Discount & Rebates
				            newParagraph = new Paragraph();
				            newParagraph.add(new Phrase(srs.getDiscountRebates(ii), font));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            cell.setPaddingRight(tpPadRight);
				            summTable.addCell(cell);

				            // Total
				            newParagraph = new Paragraph();
				            newParagraph.add(new Phrase(srs.getTotal(ii), font));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            cell.setPaddingRight(tpPadRight);
				            summTable.addCell(cell);

				            //check new page
				            if (rowCount > rowsPerPage) {
					            for (int k=0; k < 8; k++) {
						            newParagraph = new Paragraph();
						            newParagraph.add(new Phrase("", font));
						            cell = new PdfPCell(newParagraph);
						            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT + PdfPCell.BOTTOM);
						            summTable.addCell(cell);
					            }
					            //System.out.println("rowCount="+rowCount);
				                document.add(summTable);
				                summTable = new PdfPTable(summTblwidths);
				                summTable.setWidthPercentage(100);
				                document.newPage();
				            }


			            } //end for

			            // Blank Row
			            for (int k=0; k < 8; k++) {
				            newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("", font));
				            cell = new PdfPCell(newParagraph);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT + PdfPCell.BOTTOM);
				            summTable.addCell(cell);
			            }
			            rowCount++;
				    } //end if (cfiDiscountRebatesSection !=null)

				    if (cfiServiceTaxSection !=null) {
			            SummaryRepeatSection srs = new SummaryRepeatSection(cfiServiceTaxSection);
			            int lineCount = (int) srs.getTotalRowCount();

		                ///////////// Service Tax Header
		                // Column 1
			            currAccSummSection = ACC_SUMM_SERVICE_TAX;
			            newParagraph = new Paragraph();
			            newParagraph.add(new Phrase(ACC_SUMM_SERVICE_TAX, fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
			            cell.setPaddingLeft(tpPadLeft);
			            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
			            summTable.addCell(cell);
			            //Column 2
		                newParagraph = new Paragraph();
			            newParagraph.add(new Phrase("", fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            cell.setPaddingRight(tpPadRight);
			            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
			            summTable.addCell(cell);
			            //Column 3
		                newParagraph = new Paragraph();
			            newParagraph.add(new Phrase("", fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            cell.setPaddingRight(tpPadRight);
			            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
			            summTable.addCell(cell);
			            //Column 4
		                newParagraph = new Paragraph();
			            newParagraph.add(new Phrase("", fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            cell.setPaddingRight(tpPadRight);
			            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
			            summTable.addCell(cell);
			            //Column 5
		                newParagraph = new Paragraph();
			            newParagraph.add(new Phrase("", fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            cell.setPaddingRight(tpPadRight);
			            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
			            summTable.addCell(cell);
			            //Column 6
		                newParagraph = new Paragraph();
			            newParagraph.add(new Phrase("", fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            cell.setPaddingRight(tpPadRight);
			            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
			            summTable.addCell(cell);
			            //Column 7
		                newParagraph = new Paragraph();
			            newParagraph.add(new Phrase("", fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            cell.setPaddingRight(tpPadRight);
			            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
			            summTable.addCell(cell);
			            //Column 8
		                newParagraph = new Paragraph();
			            newParagraph.add(new Phrase("", fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            cell.setPaddingRight(tpPadRight);
			            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
			            summTable.addCell(cell);
			            rowCount++;

			            // Service Tax Repeat Data
			            for (int ii=0; ii < lineCount; ii++) {

				            // Blank Row
				            for (int k=0; k < 8; k++) {
					            newParagraph = new Paragraph();
					            newParagraph.add(new Phrase("", font));
					            cell = new PdfPCell(newParagraph);
					            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
					            summTable.addCell(cell);
				            }
				            rowCount++;

			                //Item
			                String[] items = srs.getItem(ii);
				            newParagraph = new Paragraph();
				            for (int jj=0; jj < items.length; jj++) {
				                newParagraph.add(new Phrase(items[jj]+"\n", font));
				                rowCount++;
				            }
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            cell.setPaddingLeft(tpPadLeft);
				            summTable.addCell(cell);

				            // Monthly Charges
				            newParagraph = new Paragraph();
				            newParagraph.add(new Phrase(srs.getMonthlyCharges(ii), font));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            cell.setPaddingRight(tpPadRight);
				            summTable.addCell(cell);

				            // Value Added Services
				            newParagraph = new Paragraph();
				            newParagraph.add(new Phrase(srs.getVAS(ii), font));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            cell.setPaddingRight(tpPadRight);
				            summTable.addCell(cell);

				            // Usage Charges
				            newParagraph = new Paragraph();
				            newParagraph.add(new Phrase(srs.getUsageCharges(ii), font));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            cell.setPaddingRight(tpPadRight);
				            summTable.addCell(cell);

				            // Other Charges
				            newParagraph = new Paragraph();
				            newParagraph.add(new Phrase(srs.getOtherCharges(ii), font));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            cell.setPaddingRight(tpPadRight);
				            summTable.addCell(cell);

				            // Service Tax
				            newParagraph = new Paragraph();
				            newParagraph.add(new Phrase(srs.getServiceTax(ii), font));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            cell.setPaddingRight(tpPadRight);
				            summTable.addCell(cell);

				            // Discount & Rebates
				            newParagraph = new Paragraph();
				            newParagraph.add(new Phrase(srs.getDiscountRebates(ii), font));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            cell.setPaddingRight(tpPadRight);
				            summTable.addCell(cell);

				            // Total
				            newParagraph = new Paragraph();
				            newParagraph.add(new Phrase(srs.getTotal(ii), font));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            cell.setPaddingRight(tpPadRight);
				            summTable.addCell(cell);

				            //check new page
				            if (rowCount > rowsPerPage) {
					            for (int k=0; k < 8; k++) {
						            newParagraph = new Paragraph();
						            newParagraph.add(new Phrase("", font));
						            cell = new PdfPCell(newParagraph);
						            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT + PdfPCell.BOTTOM);
						            summTable.addCell(cell);
					            }
					            //System.out.println("rowCount="+rowCount);
				                document.add(summTable);
				                summTable = new PdfPTable(summTblwidths);
				                summTable.setWidthPercentage(100);
				                document.newPage();
				            }


			            } //end for

			            // Blank Row
			            for (int k=0; k < 8; k++) {
				            newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("", font));
				            cell = new PdfPCell(newParagraph);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT + PdfPCell.BOTTOM);
				            summTable.addCell(cell);
			            }
			            rowCount++;
				    } //end if (cfiServiceTaxSection !=null)

		            // Total Amount
		            if (cfiAccountTotalSection !=null) {
		                //Total Item
			            newParagraph = new Paragraph();
			            newParagraph.add(new Phrase("Total Amount", font));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
			            cell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
			            cell.setPaddingTop(tpPadTop);
			            cell.setPaddingBottom(tpPadBottom);
			            cell.setPaddingLeft(tpPadLeft);
			            summTable.addCell(cell);

			            // Total Monthly Charges
			            newParagraph = new Paragraph();
			            newParagraph.add(new Phrase(cfiAccountTotalSection.getFieldText("TotalMonthlyCharges"), fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            cell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
			            cell.setPaddingTop(tpPadTop);
			            cell.setPaddingBottom(tpPadBottom);
			            cell.setPaddingRight(tpPadRight);
			            summTable.addCell(cell);

			            // Total Value Added Services
			            newParagraph = new Paragraph();
			            newParagraph.add(new Phrase(cfiAccountTotalSection.getFieldText("TotalVAS"), fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            cell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
			            cell.setPaddingTop(tpPadTop);
			            cell.setPaddingBottom(tpPadBottom);
			            cell.setPaddingRight(tpPadRight);
			            summTable.addCell(cell);

			            // Total Usage Charges
			            newParagraph = new Paragraph();
			            newParagraph.add(new Phrase(cfiAccountTotalSection.getFieldText("TotalUsageCharges"), fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            cell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
			            cell.setPaddingTop(tpPadTop);
			            cell.setPaddingBottom(tpPadBottom);
			            cell.setPaddingRight(tpPadRight);
			            summTable.addCell(cell);

			            // Total Other Charges
			            newParagraph = new Paragraph();
			            newParagraph.add(new Phrase(cfiAccountTotalSection.getFieldText("TotalOtherCharges"), fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            cell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
			            cell.setPaddingTop(tpPadTop);
			            cell.setPaddingBottom(tpPadBottom);
			            cell.setPaddingRight(tpPadRight);
			            summTable.addCell(cell);

			            // Total Service Tax
			            newParagraph = new Paragraph();
			            newParagraph.add(new Phrase(cfiAccountTotalSection.getFieldText("TotalServiceTax"), fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            cell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
			            cell.setPaddingTop(tpPadTop);
			            cell.setPaddingBottom(tpPadBottom);
			            cell.setPaddingRight(tpPadRight);
			            summTable.addCell(cell);

			            // Total Discount & Rebates
			            newParagraph = new Paragraph();
			            newParagraph.add(new Phrase(cfiAccountTotalSection.getFieldText("TotalDiscountRebates"), fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            cell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
			            cell.setPaddingTop(tpPadTop);
			            cell.setPaddingBottom(tpPadBottom);
			            cell.setPaddingRight(tpPadRight);
			            summTable.addCell(cell);

			            // Total Total
			            newParagraph = new Paragraph();
			            newParagraph.add(new Phrase(cfiAccountTotalSection.getFieldText("TotalTotal"), fontBold));
			            cell = new PdfPCell(newParagraph);
			            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            cell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
			            cell.setPaddingTop(tpPadTop);
			            cell.setPaddingBottom(tpPadBottom);
			            cell.setPaddingRight(tpPadRight);
			            summTable.addCell(cell);
			            rowCount++;
		            } // end Total Amount

				} // end if (cfiAccountDetailsSection !=null) {

				//Total Current Charges section
				if(cfiTotalCurrentChargesSection!=null){

					//Total Current Charges	- Item
					newParagraph = new Paragraph();
		            newParagraph.add(new Phrase("TOTAL CURRENT CHARGES", fontBold));
		            cell = new PdfPCell(newParagraph);
		            cell.setColspan(7);
		            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
		            cell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
		            cell.setPaddingTop(tpPadTop);
		            cell.setPaddingBottom(tpPadBottom);
		            cell.setPaddingLeft(tpPadLeft);
		            cell.setBorderWidth(2);
		            cell.setBorder(PdfPCell.BOTTOM);
		            summTable.addCell(cell);

		            //Total Current Charges	- Total
		            newParagraph = new Paragraph();
		            newParagraph.add(new Phrase(cfiTotalCurrentChargesSection.getFieldText("TotalCurrentCharges"), fontBold));
		            cell = new PdfPCell(newParagraph);
		            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
		            cell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
		            cell.setPaddingTop(tpPadTop);
		            cell.setPaddingBottom(tpPadBottom);
		            cell.setPaddingRight(tpPadRight);
		            cell.setBorderWidth(2);
		            cell.setBorder(PdfPCell.BOTTOM);
		            summTable.addCell(cell);
		            rowCount++;
				}

				// add the table to the document
				document.add(summTable);

/////// TALKTIME SUMMARY SECTION
                if (cfiTalkTimeSummarySection !=null) {
					//cfiTalkTimeSummarySection
					float talkTimeTblWidth[] = { 3.0F, 74.0F, 11.5F, 11.5F };
		            PdfPTable ttsTable = new PdfPTable(talkTimeTblWidth.length);
		            ttsTable.setWidths(talkTimeTblWidth);
		            ttsTable.setWidthPercentage(95); // percentage
					ttsTable.setHorizontalAlignment(Element.ALIGN_CENTER);

					currAccSummSection= ACC_SUMM_TALKTIME_SUMM;

					// Check new page
					if (rowsPerPage - rowCount <=11 ) {
					    document.newPage();
					} else {
					    // Empty rows
						for (int ii=0; ii <1; ii++) {
						    cell = new PdfPCell(new Phrase(" ", font));
							cell.setBorder(0);
							cell.setColspan(4);
							cell.setPaddingBottom(tpPadBottom);
							cell.setPaddingTop(tpPadTop);
							ttsTable.addCell(cell);
						}
					}

					//////////////////////ROW 1////////////////////////
					//Col 1, 2
					cell = new PdfPCell(new Phrase(ACC_SUMM_TALKTIME_SUMM, fontBigBold));
					cell.setColspan(2);
					cell.setBorder(PdfPCell.TOP + PdfPCell.LEFT);
					cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
					cell.setPaddingBottom(tpPadBottom);
					cell.setPaddingTop(tpPadTop);
					ttsTable.addCell(cell);

					//Col 3
					cell = new PdfPCell(new Phrase("RM", fontBig));
					cell.setBorder(PdfPCell.TOP );
					cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
					cell.setPaddingBottom(tpPadBottom);
					cell.setPaddingTop(tpPadTop);
					ttsTable.addCell(cell);

					//Col 4
					cell = new PdfPCell(new Phrase("RM", fontBig));
					cell.setBorder(PdfPCell.TOP + PdfPCell.RIGHT);
					cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
					cell.setPaddingBottom(tpPadBottom);
					cell.setPaddingTop(tpPadTop);
					ttsTable.addCell(cell);

					//////////////////////ROW 2////////////////////////
					//Col 1
					cell = new PdfPCell(new Phrase("", fontBold));
					cell.setBorder(PdfPCell.LEFT);
					cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
					cell.setPaddingBottom(tpPadBottom);
					cell.setPaddingTop(tpPadTop);
					cell.setBackgroundColor(colorGrey);
					ttsTable.addCell(cell);

					//Col 2
					phrase = new Phrase();
					chunk = new Chunk("Balance talktime from previous month", fontBold);
					phrase.add(chunk);
					chunk = new Chunk("  / Baki masa panggilan dari bulan lepas", fontItalic);
					phrase.add(chunk);
	                cell = new PdfPCell(phrase);
					cell.setBorder(0);
					cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
					cell.setPaddingBottom(tpPadBottom);
					cell.setPaddingTop(tpPadTop);
					cell.setBackgroundColor(colorGrey);
					ttsTable.addCell(cell);

					//Col 3
					cell = new PdfPCell(new Phrase(cfiTalkTimeSummarySection.getFieldText("BalancePreviousMonth"), font));
					cell.setBorder(0);
					cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
					cell.setPaddingBottom(tpPadBottom);
					cell.setPaddingTop(tpPadTop);
					cell.setBackgroundColor(colorGrey);
					ttsTable.addCell(cell);

					//Col 4
					cell = new PdfPCell(new Phrase("", font));
					cell.setBorder(PdfPCell.RIGHT);
					cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
					cell.setPaddingBottom(tpPadBottom);
					cell.setPaddingTop(tpPadTop);
					cell.setBackgroundColor(colorGrey);
					ttsTable.addCell(cell);

					//////////////////////ROW 3////////////////////////
					//Col 1
					cell = new PdfPCell(new Phrase("(+)", fontBold));
					cell.setBorder(PdfPCell.LEFT);
					cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
					cell.setPaddingBottom(tpPadBottom);
					cell.setPaddingTop(tpPadTop);
					ttsTable.addCell(cell);

					//Col 2
					phrase = new Phrase();
					chunk = new Chunk("Talktime from current month's subscription", fontBold);
					phrase.add(chunk);
					chunk = new Chunk("  / Masa panggilan dari Langganan bulanan*", fontItalic);
					phrase.add(chunk);
	                cell = new PdfPCell(phrase);
					cell.setBorder(0);
					cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
					cell.setPaddingBottom(tpPadBottom);
					cell.setPaddingTop(tpPadTop);
					ttsTable.addCell(cell);

					//Col 3
					cell = new PdfPCell(new Phrase(cfiTalkTimeSummarySection.getFieldText("CurrentMonthSubscription"), fontUnderline));
					cell.setBorder(0);
					cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
					cell.setPaddingBottom(tpPadBottom);
					cell.setPaddingTop(tpPadTop);
					ttsTable.addCell(cell);

					//Col 4
					cell = new PdfPCell(new Phrase("", font));
					cell.setBorder(PdfPCell.RIGHT);
					cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
					cell.setPaddingBottom(tpPadBottom);
					cell.setPaddingTop(tpPadTop);
					ttsTable.addCell(cell);

					//////////////////////ROW 4////////////////////////
					//Col 1
					cell = new PdfPCell(new Phrase("", fontBold));
					cell.setBorder(PdfPCell.LEFT);
					cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
					cell.setPaddingBottom(tpPadBottom);
					cell.setPaddingTop(tpPadTop);
					cell.setBackgroundColor(colorGrey);
					ttsTable.addCell(cell);

					//Col 2
					phrase = new Phrase();
					chunk = new Chunk("Available talktime", fontBold);
					phrase.add(chunk);
					chunk = new Chunk("  / Masa panggilan", fontItalic);
					phrase.add(chunk);
	                cell = new PdfPCell(phrase);
					cell.setBorder(0);
					cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
					cell.setPaddingBottom(tpPadBottom);
					cell.setPaddingTop(tpPadTop);
					cell.setBackgroundColor(colorGrey);
					ttsTable.addCell(cell);

					//Col 3
					cell = new PdfPCell(new Phrase(cfiTalkTimeSummarySection.getFieldText("TotalAvailable"), font));
					cell.setBorder(0);
					cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
					cell.setPaddingBottom(tpPadBottom);
					cell.setPaddingTop(tpPadTop);
					cell.setBackgroundColor(colorGrey);
					ttsTable.addCell(cell);

					//Col 4
					cell = new PdfPCell(new Phrase("", font));
					cell.setBorder(PdfPCell.RIGHT);
					cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
					cell.setPaddingBottom(tpPadBottom);
					cell.setPaddingTop(tpPadTop);
					cell.setBackgroundColor(colorGrey);
					ttsTable.addCell(cell);

					//////////////////////ROW 5////////////////////////
					//Col 1
					cell = new PdfPCell(new Phrase("(-)", fontBold));
					cell.setBorder(PdfPCell.LEFT);
					cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
					cell.setPaddingBottom(tpPadBottom);
					cell.setPaddingTop(tpPadTop);
					ttsTable.addCell(cell);

					//Col 2
					phrase = new Phrase();
					chunk = new Chunk("Amount deducted from available talktime", fontBold);
					phrase.add(chunk);
					chunk = new Chunk("  / Jumlah yang ditolak dari jumlah masa panggilan**", fontItalic);
					phrase.add(chunk);
	                cell = new PdfPCell(phrase);
					cell.setBorder(0);
					cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
					cell.setPaddingBottom(tpPadBottom);
					cell.setPaddingTop(tpPadTop);
					ttsTable.addCell(cell);

					//Col 3
					cell = new PdfPCell(new Phrase("", font));
					cell.setBorder(0);
					cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
					cell.setPaddingBottom(tpPadBottom);
					cell.setPaddingTop(tpPadTop);
					ttsTable.addCell(cell);

					//Col 4
					cell = new PdfPCell(new Phrase(cfiTalkTimeSummarySection.getFieldText("AmountDeducted"), font));
					cell.setBorder(PdfPCell.RIGHT);
					cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
					cell.setPaddingBottom(tpPadBottom);
					cell.setPaddingTop(tpPadTop);
					ttsTable.addCell(cell);

					//////////////////////ROW 6////////////////////////
					//Col 1
					cell = new PdfPCell(new Phrase("(-)", fontBold));
					cell.setBorder(PdfPCell.LEFT);
					cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
					cell.setPaddingBottom(tpPadBottom);
					cell.setPaddingTop(tpPadTop);
					cell.setBackgroundColor(colorGrey);
					ttsTable.addCell(cell);

					//Col 2
					phrase = new Phrase();
					chunk = new Chunk("Balance talktime to be carried forward", fontBold);
					phrase.add(chunk);
					chunk = new Chunk("  / Masa panggilan dibawa ke depan", fontItalic);
					phrase.add(chunk);
	                cell = new PdfPCell(phrase);
					cell.setBorder(0);
					cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
					cell.setPaddingBottom(tpPadBottom);
					cell.setPaddingTop(tpPadTop);
					cell.setBackgroundColor(colorGrey);
					ttsTable.addCell(cell);

					//Col 3
					cell = new PdfPCell(new Phrase("", font));
					cell.setBorder(0);
					cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
					cell.setPaddingBottom(tpPadBottom);
					cell.setBackgroundColor(colorGrey);
					cell.setPaddingTop(tpPadTop);
					ttsTable.addCell(cell);

					//Col 4
					cell = new PdfPCell(new Phrase(cfiTalkTimeSummarySection.getFieldText("BalanceCarriedForward"), font));
					cell.setBorder(PdfPCell.RIGHT);
					cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
					cell.setPaddingBottom(tpPadBottom);
					cell.setPaddingTop(tpPadTop);
					cell.setBackgroundColor(colorGrey);
					ttsTable.addCell(cell);

					//////////////////////ROW 7////////////////////////
					//Col 1
					cell = new PdfPCell(new Phrase("", fontBold));
					cell.setBorder(PdfPCell.LEFT);
					cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
					cell.setPaddingBottom(tpPadBottom);
					cell.setPaddingTop(tpPadTop);
					ttsTable.addCell(cell);

					//Col 2
					phrase = new Phrase();
					chunk = new Chunk("Balance talktime lost", fontBold);
					phrase.add(chunk);
					chunk = new Chunk("  / Baki masa panggilan yang hilang", fontItalic);
					phrase.add(chunk);
	                cell = new PdfPCell(phrase);
					cell.setBorder(0);
					cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
					cell.setPaddingBottom(tpPadBottom);
					cell.setPaddingTop(tpPadTop);
					ttsTable.addCell(cell);

					//Col 3
					cell = new PdfPCell(new Phrase("", font));
					cell.setBorder(0);
					cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
					cell.setPaddingBottom(tpPadBottom);
					cell.setPaddingTop(tpPadTop);
					ttsTable.addCell(cell);

					//Col 4
					cell = new PdfPCell(new Phrase(cfiTalkTimeSummarySection.getFieldText("BalanceLost"), font));
					cell.setBorder(PdfPCell.RIGHT);
					cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
					cell.setPaddingBottom(tpPadBottom);
					cell.setPaddingTop(tpPadTop);
					ttsTable.addCell(cell);

					//////////////////////ROW 8////////////////////////
					//Col 1, 2
					cell = new PdfPCell(new Phrase(" ", fontBold));
					cell.setBorder(PdfPCell.LEFT + PdfPCell.BOTTOM);
					cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
					cell.setPaddingBottom(tpPadBottom);
					cell.setPaddingTop(tpPadTop);
					cell.setBackgroundColor(colorGrey);
					ttsTable.addCell(cell);

					cell = new PdfPCell(new Phrase(" ", fontBold));
					cell.setBorder(PdfPCell.BOTTOM);
					cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
					cell.setPaddingBottom(tpPadBottom);
					cell.setPaddingTop(tpPadTop);
					cell.setBackgroundColor(colorGrey);
					ttsTable.addCell(cell);

					//Col 3
					cell = new PdfPCell(new Phrase(" ", font));
					cell.setBorder(PdfPCell.BOTTOM);
					cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
					cell.setPaddingBottom(tpPadBottom);
					cell.setPaddingTop(tpPadTop);
					cell.setBackgroundColor(colorGrey);
					ttsTable.addCell(cell);

					//Col 4
					cell = new PdfPCell(new Phrase(" ", font));
					cell.setBorder(PdfPCell.RIGHT + PdfPCell.BOTTOM);
					cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
					cell.setPaddingBottom(6);
					cell.setPaddingTop(6);
					cell.setBackgroundColor(colorGrey);
					ttsTable.addCell(cell);

					//NOTE: The maximum talktime to be carried forward is xxxx
					//////////////////////ROW 9////////////////////////
					//Col 1,2,3,4
					phrase = new Phrase();
					chunk = new Chunk("NOTE: The maximum talktime to be carried forward is RM " + cfiTalkTimeSummarySection.getFieldText("MaximumCarriedForward"), font);
					phrase.add(chunk);
					chunk = new Chunk("  / Jumlah yang boleh dibawa ke depan ialah RM " + cfiTalkTimeSummarySection.getFieldText("MaximumCarriedForward"), fontItalic);
					phrase.add(chunk);
	                cell = new PdfPCell(phrase);
					cell.setColspan(4);
					cell.setBorder(0);
					cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
					cell.setPaddingBottom(tpPadBottom);
					cell.setPaddingTop(tpPadTop);
					ttsTable.addCell(cell);

					document.add(ttsTable);
					rowCount+=11;
                } // end if (cfiTalkTimeSummarySection !=null)

				currAccSummSection = "";
				isAccSumm = false;

            } catch (DocumentException de) {
                System.err.println(de.getMessage());
                de.printStackTrace();
            } catch (Exception ex) {
                System.err.println(ex.getMessage());
                ex.printStackTrace();
            }
        }

    /**
     * add the Details of Charges to the table
     *
     * @param writer
     * @param document
     */
        public void addDetailsOfChargesSec(PdfWriter writer, Document document, StatementSection cfiDetailsOfChargesSection, StatementSection cfiRootSection) {

            // padding size for the cell
			int tpPadBottom = 5;
			int tpPadTop = 5;
			int tpPadRight = 5;
			int tpPadLeft = 5;

            try {

                // font used in this section
            	Font font = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL,new Color(0, 0, 0));
				Font fontItalic = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.ITALIC,new Color(0, 0, 0));
				Font fontBold = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.BOLD,new Color(0, 0, 0));
				Font fontSpace = FontFactory.getFont(FontFactory.HELVETICA, 10, Font.NORMAL,new Color(0, 0, 0));
				Font bigFontItalic = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.ITALIC,new Color(0, 0, 0));
				Font bigFontBold = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD,new Color(0, 0, 0));

    			//Phone Number section
				if(cfiDetailsOfChargesSection!=null){

		            //Total Line Charges Section Part
					StatementSection PhoneNumberRepeatSection = null;
           			long DetailLines2 = cfiDetailsOfChargesSection.getSectionCount("PhoneNumberSection");

            		for (int k = 0; k < DetailLines2; k++) {

            			// transaction detail table column widths
                        float headerwidths[] = { 22.0F, 8.0F, 6.0F, 6.0F, 6.0F }; // percentage
                        PdfPTable transTable = new PdfPTable(headerwidths.length);
                        transTable.setWidths(headerwidths);
                        transTable.setWidthPercentage(100); // percentage

                        //Get data field from root section
            			final String AccNo = EbppxUtil.htmlEncode(cfiRootSection.getFieldText("AccountNumber"));
            			final String StmtDt = EbppxUtil.htmlEncode(cfiRootSection.getFieldText("StatementDate"));
            			final String AccName = EbppxUtil.htmlEncode(cfiRootSection.getFieldText("AccountName"));
            		  	final String TotalAmountDue = EbppxUtil.htmlEncode(cfiRootSection.getFieldText("TotalAmountDue"));

            		    // Get the row section
            			PhoneNumberRepeatSection = cfiDetailsOfChargesSection.getRepeatSection("PhoneNumberSection", k);

            			StatementSection cfiItemsWithoutRebateSection = PhoneNumberRepeatSection.getSection("ItemsWithoutRebateSection");
		    		   	StatementSection cfiItemsWithRebateSection = PhoneNumberRepeatSection.getSection("ItemWithRebateSection");

		    		   	//Get Items Without Rebate section
		    		   	StatementSection cfiPaymentsSection = null;
		    		   	StatementSection cfiAdjustmentsSection = null;
		    		   	StatementSection cfiAdjustmentsServiceTaxSection = null;

		    		   	if (cfiItemsWithoutRebateSection !=null) {
			    		   	cfiPaymentsSection = cfiItemsWithoutRebateSection.getSection("PaymentsSection");
			    		   	cfiAdjustmentsSection = cfiItemsWithoutRebateSection.getSection("AdjustmentsSection");;
			    		   	cfiAdjustmentsServiceTaxSection = cfiItemsWithoutRebateSection.getSection("AdjustmentsServiceTaxSection");
		    		   	}

		                //Declaration
						Chunk chunk;
						Phrase phrase;
		                PdfPCell cell = null;
		                Image img = null;
		                Paragraph newParagraph = null;

		                //Title
						phrase = new Phrase();
						chunk = new Chunk("DETAILS OF CHARGES\n", bigFontBold);
						phrase.add(chunk);
						chunk = new Chunk("BUTIR-BUTIR CAJ", bigFontItalic);
						phrase.add(chunk);
		                cell = new PdfPCell(phrase);
						cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
						cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
						cell.setColspan(5);
						cell.setBorderWidth(0);
						transTable.addCell(cell);

						//Add blank row
						cell = new PdfPCell(new Phrase("",fontBold));
						cell.setColspan(5);
						cell.setBorderWidth(0);
						transTable.addCell(cell);

						//Statement Date
						phrase = new Phrase();
						chunk = new Chunk("Statement Date / ", fontBold);
						phrase.add(chunk);
						chunk = new Chunk("Tarikh Penyata   ", fontItalic);
						phrase.add(chunk);
						chunk = new Chunk(":  " + StmtDt, fontBold);
						phrase.add(chunk);
		                cell = new PdfPCell(phrase);
						cell.setHorizontalAlignment(Element.ALIGN_LEFT);
						cell.setColspan(5);
						cell.setBorderWidth(0);
						transTable.addCell(cell);

						//Add blank row
						cell = new PdfPCell(new Phrase("",fontBold));
						cell.setColspan(5);
						cell.setBorderWidth(0);
						transTable.addCell(cell);

						//Phone Number
						phrase = new Phrase();
						chunk = new Chunk("Phone Number / ", fontBold);
						phrase.add(chunk);
						chunk = new Chunk("No.Telefon          ", fontItalic);
						phrase.add(chunk);
						chunk = new Chunk("" + PhoneNumberRepeatSection.getField("PhoneNumber"), fontBold);
						phrase.add(chunk);
		                cell = new PdfPCell(phrase);
						cell.setHorizontalAlignment(Element.ALIGN_LEFT);
						cell.setColspan(5);
						cell.setBorderWidth(0);
						transTable.addCell(cell);

						//Add blank row
						cell = new PdfPCell(new Phrase("",fontBold));
						cell.setColspan(5);
						cell.setBorderWidth(0);
						transTable.addCell(cell);

						if(!(PhoneNumberRepeatSection.getField("SimNumber") == null)){
						//Sim Number
						phrase = new Phrase();
						chunk = new Chunk("Sim Number / ", fontBold);
						phrase.add(chunk);
						chunk = new Chunk("No.Sim           	     ", fontItalic);
						phrase.add(chunk);
						chunk = new Chunk("    " + PhoneNumberRepeatSection.getField("SimNumber"), fontBold);
						phrase.add(chunk);
						cell = new PdfPCell(phrase);
						cell.setHorizontalAlignment(Element.ALIGN_LEFT);
						cell.setColspan(5);
						cell.setBorderWidth(0);
						transTable.addCell(cell);

						//Add blank row
						cell = new PdfPCell(new Phrase("",fontBold));
						cell.setColspan(5);
						cell.setBorderWidth(0);
						transTable.addCell(cell);
						}

						//Account Name
						phrase = new Phrase();
						chunk = new Chunk("Account Name / ", fontBold);
						phrase.add(chunk);
						chunk = new Chunk("Nama Akaun       ", fontItalic);
						phrase.add(chunk);
						//sub name added 2013-Jan
						if(PhoneNumberRepeatSection.getField("SubAccName") != null){
							chunk = new Chunk(" " + PhoneNumberRepeatSection.getField("SubAccName"), fontBold);
						}else{
							chunk = new Chunk(": " + AccName, fontBold);
						}
						phrase.add(chunk);
		                cell = new PdfPCell(phrase);
						cell.setHorizontalAlignment(Element.ALIGN_LEFT);
						cell.setColspan(5);
						cell.setBorderWidth(0);
						transTable.addCell(cell);

						// Add 5 blank lines
						for (int j = 0; j < 10; j++) {
							cell = new PdfPCell(new Phrase("",fontBold));
							cell.setColspan(5);
							cell.setBorderWidth(0);
							transTable.addCell(cell);
						}

//////////////////////////Items Without Rebate section
						if(cfiItemsWithoutRebateSection!=null){
							//Header 1
							//Column 1 Row 1 Header 1 - Item
							newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("Item", fontBold));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.TOP);
				            cell.setPaddingLeft(tpPadLeft);
				            cell.setPaddingTop(tpPadTop);
				            cell.setGrayFill(0.8f);
				            transTable.addCell(cell);

				            //Column 2-3 Row 1 Header 1 - Date/Period
							newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("Date/Period", fontBold));
				            cell = new PdfPCell(newParagraph);
				            cell.setColspan(2);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
				            cell.setBorder(PdfPCell.TOP);
				            cell.setPaddingTop(tpPadTop);
				            cell.setGrayFill(0.8f);
				            transTable.addCell(cell);

				            //Column 4 Row 1 Header 1 - Amount (RM)
							newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("Amount (RM)", fontBold));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setBorder(PdfPCell.TOP);
				            cell.setPaddingTop(tpPadTop);
				            cell.setGrayFill(0.8f);
				            transTable.addCell(cell);

				            //Column 5 Row 1 Header 1 - Total (RM)
							newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("Total (RM)", fontBold));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setBorder(PdfPCell.TOP + PdfPCell.RIGHT);
				            cell.setPaddingTop(tpPadTop);
				            cell.setPaddingRight(tpPadRight);
				            cell.setGrayFill(0.8f);
				            transTable.addCell(cell);

				            //Header 2
							//Column 1 Row 1 Header 2 - Item
							newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("Item", fontItalic));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.BOTTOM);
				            cell.setPaddingBottom(tpPadBottom);
				            cell.setPaddingLeft(tpPadLeft);
				            cell.setGrayFill(0.8f);
				            transTable.addCell(cell);

				            //Column 2-3 Row 1 Header 2 - Tarikh/Tempoh
							newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("Tarikh/Tempoh", fontItalic));
				            cell = new PdfPCell(newParagraph);
				            cell.setColspan(2);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
				            cell.setBorder(PdfPCell.BOTTOM);
				            cell.setPaddingBottom(tpPadBottom);
				            cell.setGrayFill(0.8f);
				            transTable.addCell(cell);

				            //Column 4 Row 1 Header 2 - Amaun (RM)
							newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("Amaun (RM))", fontItalic));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setBorder(PdfPCell.BOTTOM);
				            cell.setPaddingBottom(tpPadBottom);
				            cell.setGrayFill(0.8f);
				            transTable.addCell(cell);

				            //Column 5 Row 1 Header 2 - Jumlah (RM)
							newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("Jumlah (RM)", fontItalic));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setBorder(PdfPCell.BOTTOM + PdfPCell.RIGHT);
				            cell.setPaddingBottom(tpPadBottom);
				            cell.setPaddingRight(tpPadRight);
				            cell.setGrayFill(0.8f);
				            transTable.addCell(cell);

				            // SET THE HEADER ROWS
							transTable.setHeaderRows(19);

				            //Payments repeat section
							if(cfiPaymentsSection!=null){

								//Payments Header
								newParagraph = new Paragraph();
					            newParagraph.add(new Phrase("Payments", fontBold));
					            cell = new PdfPCell(newParagraph);
					            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
					            cell.setBorder(PdfPCell.BOTTOM);
					            cell.setPaddingBottom(tpPadBottom);
					            cell.setPaddingTop(tpPadTop);
					            cell.setPaddingLeft(tpPadLeft);
					            cell.setColspan(5);
					            transTable.addCell(cell);

					            //Payments Repeat Section Part
								StatementSection PaymentsRepeatSection = null;
			           			long DetailLines = cfiPaymentsSection.getSectionCount("RepeatSection");

			            		for (int i = 0; i < DetailLines; i++) {
			            		    // Get the row section
			            		    PaymentsRepeatSection = cfiPaymentsSection.getRepeatSection("RepeatSection", i);

			            			//Column 1 : Item
			            			if(PaymentsRepeatSection.getField("Item")!=null)
			            	    	{
			            	    		cell = new PdfPCell(new Phrase(PaymentsRepeatSection.getField("Item").asString(), font));
			            	    	}
			            	    	else
			            	    	{
			            	    		cell = new PdfPCell(new Phrase("", font));
			            	    	}
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
			            	    	cell.setPaddingLeft(tpPadLeft);
			            	    	cell.setBorderWidth(0);
			            	    	transTable.addCell(cell);

			            	    	//Column 2-3 : Date/Period
			            	    	if(PaymentsRepeatSection.getField("Date")!=null)
			            	    	{
			            	    		cell = new PdfPCell(new Phrase(PaymentsRepeatSection.getField("Date").asString(), font));
			            	    	}
			            	    	else
			            	    	{
			            	    		cell = new PdfPCell(new Phrase("", font));
			            	    	}
		 	            	    	cell.setColspan(2);
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
		 	            	    	cell.setBorderWidth(0);
		 	            	    	transTable.addCell(cell);

			            	    	//Column 4 : Amount
		 	            	    	if(PaymentsRepeatSection.getField("Amount")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(PaymentsRepeatSection.getField("Amount").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            	    	cell.setBorderWidth(0);
			            	    	cell.setPaddingRight(tpPadRight);
			            	    	transTable.addCell(cell);

			            	    	//Column 5 : Total
			            	    	if(PaymentsRepeatSection.getField("Total")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(PaymentsRepeatSection.getField("Total").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            	    	cell.setPaddingRight(tpPadRight);
			            	    	cell.setBorderWidth(0);
			            	    	transTable.addCell(cell);
								}//end For

			            		//Add a Blank Line
			            		cell = new PdfPCell(new Phrase("",fontBold));
		    					cell.setColspan(5);
		    					cell.setBorderWidth(0);
		    					transTable.addCell(cell);
							} // end if(cfiPaymentsSection!=null)

				            //Adjustments repeat section
							if(cfiAdjustmentsSection!=null){

								//Adjustments Header
								newParagraph = new Paragraph();
					            newParagraph.add(new Phrase("Adjustments", fontBold));
					            cell = new PdfPCell(newParagraph);
					            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
					            cell.setBorder(PdfPCell.BOTTOM);
					            cell.setPaddingBottom(tpPadBottom);
					            cell.setPaddingTop(tpPadTop);
					            cell.setPaddingLeft(tpPadLeft);
					            cell.setColspan(5);
					            transTable.addCell(cell);

					            //Adjustements Repeat Section Part
								StatementSection AdjustmentsRepeatSection = null;
			           			long DetailLines = cfiAdjustmentsSection.getSectionCount("RepeatSection");

			            		for (int i = 0; i < DetailLines; i++) {
			            		    // Get the row section
			            		    AdjustmentsRepeatSection = cfiAdjustmentsSection.getRepeatSection("RepeatSection", i);

			            			//Column 1 : Item
			            			if(AdjustmentsRepeatSection.getField("Item")!=null)
			            	    	{
			            	    		cell = new PdfPCell(new Phrase(AdjustmentsRepeatSection.getField("Item").asString(), font));
			            	    	}
			            	    	else
			            	    	{
			            	    		cell = new PdfPCell(new Phrase("", font));
			            	    	}
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
			            	    	cell.setPaddingLeft(tpPadLeft);
			            	    	cell.setBorderWidth(0);
			            	    	transTable.addCell(cell);

			            	    	//Column 2-3 : Date/Period
			            	    	if(AdjustmentsRepeatSection.getField("Date")!=null)
			            	    	{
			            	    		cell = new PdfPCell(new Phrase(AdjustmentsRepeatSection.getField("Date").asString(), font));
			            	    	}
			            	    	else
			            	    	{
			            	    		cell = new PdfPCell(new Phrase("", font));
			            	    	}
		 	            	    	cell.setColspan(2);
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
		 	            	    	cell.setBorderWidth(0);
		 	            	    	transTable.addCell(cell);

			            	    	//Column 4 : Amount
		 	            	    	if(AdjustmentsRepeatSection.getField("Amount")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(AdjustmentsRepeatSection.getField("Amount").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            	    	cell.setBorderWidth(0);
			            	    	cell.setPaddingRight(tpPadRight);
			            	    	transTable.addCell(cell);

			            	    	//Column 5 : Total
			            	    	if(AdjustmentsRepeatSection.getField("Total")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(AdjustmentsRepeatSection.getField("Total").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            	    	cell.setPaddingRight(tpPadRight);
			            	    	cell.setBorderWidth(0);
			            	    	transTable.addCell(cell);
								}//end For

			            		//Add a Blank Line
			            		cell = new PdfPCell(new Phrase("",fontBold));
		    					cell.setColspan(5);
		    					cell.setBorderWidth(0);
		    					transTable.addCell(cell);
							} // end if(cfiAdjustmentsSection!=null)

				            //Adjustment - Service Tax repeat section
							if(cfiAdjustmentsServiceTaxSection!=null){

								//Adjustments Header
								newParagraph = new Paragraph();
					            newParagraph.add(new Phrase("Adjustment - Service Tax", fontBold));
					            cell = new PdfPCell(newParagraph);
					            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
					            cell.setBorder(PdfPCell.BOTTOM);
					            cell.setPaddingBottom(tpPadBottom);
					            cell.setPaddingTop(tpPadTop);
					            cell.setPaddingLeft(tpPadLeft);
					            cell.setColspan(5);
					            transTable.addCell(cell);

					            //Adjustment - Service Tax Repeat Section Part
								StatementSection AdjustmentsServiceTaxRepeatSection = null;
			           			long DetailLines = cfiAdjustmentsServiceTaxSection.getSectionCount("RepeatSection");

			            		for (int i = 0; i < DetailLines; i++) {
			            		    // Get the row section
			            		    AdjustmentsServiceTaxRepeatSection = cfiAdjustmentsServiceTaxSection.getRepeatSection("RepeatSection", i);

			            			//Column 1 : Item
			            			if(AdjustmentsServiceTaxRepeatSection.getField("Item")!=null)
			            	    	{
			            	    		cell = new PdfPCell(new Phrase(AdjustmentsServiceTaxRepeatSection.getField("Item").asString(), font));
			            	    	}
			            	    	else
			            	    	{
			            	    		cell = new PdfPCell(new Phrase("", font));
			            	    	}
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
			            	    	cell.setPaddingLeft(tpPadLeft);
			            	    	cell.setBorderWidth(0);
			            	    	transTable.addCell(cell);

			            	    	//Column 2-3 : Date/Period
			            	    	if(AdjustmentsServiceTaxRepeatSection.getField("Date")!=null)
			            	    	{
			            	    		cell = new PdfPCell(new Phrase(AdjustmentsServiceTaxRepeatSection.getField("Date").asString(), font));
			            	    	}
			            	    	else
			            	    	{
			            	    		cell = new PdfPCell(new Phrase("", font));
			            	    	}
		 	            	    	cell.setColspan(2);
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
		 	            	    	cell.setBorderWidth(0);
		 	            	    	transTable.addCell(cell);

			            	    	//Column 4 : Amount
		 	            	    	if(AdjustmentsServiceTaxRepeatSection.getField("Amount")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(AdjustmentsServiceTaxRepeatSection.getField("Amount").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            	    	cell.setBorderWidth(0);
			            	    	cell.setPaddingRight(tpPadRight);
			            	    	transTable.addCell(cell);

			            	    	//Column 5 : Total
			            	    	if(AdjustmentsServiceTaxRepeatSection.getField("Total")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(AdjustmentsServiceTaxRepeatSection.getField("Total").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            	    	cell.setPaddingRight(tpPadRight);
			            	    	cell.setBorderWidth(0);
			            	    	transTable.addCell(cell);
								}//end For

			            		//Add a Blank Line
			            		cell = new PdfPCell(new Phrase("",fontBold));
		    					cell.setColspan(5);
		    					cell.setBorderWidth(0);
		    					transTable.addCell(cell);
							} // end if(cfiAdjustmentsServiceTaxSection!=null)

		            		//Add a Blank Line
		            		cell = new PdfPCell(new Phrase("",fontBold));
	    					cell.setColspan(5);
	    					cell.setBorderWidth(0);
	    					transTable.addCell(cell);

						} // end if(cfiItemsWithoutRebateSection!=null)

//////////////////////////Items With Rebate section
						if(cfiItemsWithRebateSection!=null){

							//Get Items With Rebate section
							StatementSection cfiTotalLineChargesSection = cfiItemsWithRebateSection.getSection("TotalLineChargesSection");
							StatementSection cfiDiscountsAndRebateSection = cfiItemsWithRebateSection.getSection("DiscountAndRebatesSection");
							StatementSection cfiOtherChargesAndCreditSection = cfiItemsWithRebateSection.getSection("OtherChargesAndCreditSection");
							StatementSection cfiServiceTaxSection = cfiItemsWithRebateSection.getSection("ServiceTaxSection");
							StatementSection cfiAdvantageSavingsSection = cfiItemsWithRebateSection.getSection("AdvantageSavingsSection");
							StatementSection cfiAccessChargesSection= cfiItemsWithRebateSection.getSection("AccessChargesSection");
							StatementSection cfiRegistrationChargesSection= cfiItemsWithRebateSection.getSection("RegistrationChargesSection");
							StatementSection cfiMonthlyChargesSection = cfiItemsWithRebateSection.getSection("MonthlyChargesSection");
							StatementSection cfiValueAddedServciesSection = cfiItemsWithRebateSection.getSection("ValueAddedServicesSection");
							StatementSection cfiUsageChargesSection = cfiItemsWithRebateSection.getSection("UsageChargesSection");

							//Header 1
							//Column 1 Row 1 Header 1 - Item
							newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("Item", fontBold));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.TOP);
				            cell.setPaddingLeft(tpPadLeft);
				            cell.setPaddingTop(tpPadTop);
				            cell.setGrayFill(0.8f);
				            transTable.addCell(cell);

				            //Column 2 Row 1 Header 1 - Date/Period
							newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("Date/Period", fontBold));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
				            cell.setBorder(PdfPCell.TOP);
				            cell.setPaddingTop(tpPadTop);
				            cell.setGrayFill(0.8f);
				            transTable.addCell(cell);

				            //Column 3 Row 1 Header 1 - Rebate (RM)
							newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("Rebate (RM)", fontBold));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
				            cell.setBorder(PdfPCell.TOP);
				            cell.setPaddingTop(tpPadTop);
				            cell.setGrayFill(0.8f);
				            transTable.addCell(cell);

				            //Column 4 Row 1 Header 1 - Amount (RM)
							newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("Amount (RM)", fontBold));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setBorder(PdfPCell.TOP);
				            cell.setPaddingTop(tpPadTop);
				            cell.setGrayFill(0.8f);
				            transTable.addCell(cell);

				            //Column 5 Row 1 Header 1 - Total (RM)
							newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("Total (RM)", fontBold));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setBorder(PdfPCell.TOP + PdfPCell.RIGHT);
				            cell.setPaddingTop(tpPadTop);
				            cell.setPaddingRight(tpPadRight);
				            cell.setGrayFill(0.8f);
				            transTable.addCell(cell);

				            //Header 2
							//Column 1 Row 1 Header 2 - Item
							newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("Item", fontItalic));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.BOTTOM);
				            cell.setPaddingBottom(tpPadBottom);
				            cell.setPaddingLeft(tpPadLeft);
				            cell.setGrayFill(0.8f);
				            transTable.addCell(cell);

				            //Column 2 Row 1 Header 2 - Tarikh/Tempoh
							newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("Tarikh/Tempoh", fontItalic));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
				            cell.setBorder(PdfPCell.BOTTOM);
				            cell.setPaddingBottom(tpPadBottom);
				            cell.setGrayFill(0.8f);
				            transTable.addCell(cell);

				            //Column 3 Row 1 Header 2 - Rebat (RM)
							newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("Rebat (RM)", fontItalic));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
				            cell.setBorder(PdfPCell.BOTTOM);
				            cell.setPaddingBottom(tpPadBottom);
				            cell.setGrayFill(0.8f);
				            transTable.addCell(cell);

				            //Column 4 Row 1 Header 2 - Amaun (RM)
							newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("Amaun (RM))", fontItalic));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setBorder(PdfPCell.BOTTOM);
				            cell.setPaddingBottom(tpPadBottom);
				            cell.setGrayFill(0.8f);
				            transTable.addCell(cell);

				            //Column 5 Row 1 Header 2 - Jumlah (RM)
							newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("Jumlah (RM)", fontItalic));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setBorder(PdfPCell.BOTTOM + PdfPCell.RIGHT);
				            cell.setPaddingBottom(tpPadBottom);
				            cell.setPaddingRight(tpPadRight);
				            cell.setGrayFill(0.8f);
				            transTable.addCell(cell);

				            // SET THE HEADER ROWS
							transTable.setHeaderRows(19);

				            //Monthly Charges repeat section
							if(cfiMonthlyChargesSection!=null){

								//Monthly Charges Header
								newParagraph = new Paragraph();
					            newParagraph.add(new Phrase("Monthly Charges", fontBold));
					            cell = new PdfPCell(newParagraph);
					            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
					            cell.setBorder(PdfPCell.BOTTOM);
					            cell.setPaddingBottom(tpPadBottom);
					            cell.setPaddingTop(tpPadTop);
					            cell.setPaddingLeft(tpPadLeft);
					            cell.setColspan(5);
					            transTable.addCell(cell);

					            //Monthly Charges Repeat Section Part
								StatementSection MonthlyChargesRepeatSection = null;
			           			long DetailLines = cfiMonthlyChargesSection.getSectionCount("RepeatSection");

			            		for (int i = 0; i < DetailLines; i++) {
			            		    // Get the row section
			            			MonthlyChargesRepeatSection = cfiMonthlyChargesSection.getRepeatSection("RepeatSection", i);

			            			//Column 1 : Item
			            			if(MonthlyChargesRepeatSection.getField("Item")!=null)
			            	    	{
			            	    		cell = new PdfPCell(new Phrase(MonthlyChargesRepeatSection.getField("Item").asString(), font));
			            	    	}
			            	    	else
			            	    	{
			            	    		cell = new PdfPCell(new Phrase("", font));
			            	    	}
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
			            	    	cell.setPaddingLeft(tpPadLeft);
			            	    	cell.setBorderWidth(0);
			            	    	transTable.addCell(cell);

			            	    	//Column 2 : Date/Period
			            	    	if(MonthlyChargesRepeatSection.getField("Date")!=null)
			            	    	{
			            	    		cell = new PdfPCell(new Phrase(MonthlyChargesRepeatSection.getField("Date").asString(), font));
			            	    	}
			            	    	else
			            	    	{
			            	    		cell = new PdfPCell(new Phrase("", font));
			            	    	}
		 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
		 	            	    	cell.setBorderWidth(0);
		 	            	    	transTable.addCell(cell);

			            	    	//Column 3 : Rebate
			            	    	if(MonthlyChargesRepeatSection.getField("Rebate")!=null)
			            	    	{
			            	    		cell = new PdfPCell(new Phrase(MonthlyChargesRepeatSection.getField("Rebate").asString(), font));
			            	    	}
			            	    	else
			            	    	{
			            	    		cell = new PdfPCell(new Phrase("", font));
			            	    	}
		 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
		 	            	    	cell.setBorderWidth(0);
		 	            	    	cell.setPaddingRight(tpPadRight);
		 	            	    	transTable.addCell(cell);

			            	    	//Column 4 : Amount
		 	            	    	if(MonthlyChargesRepeatSection.getField("Amount")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(MonthlyChargesRepeatSection.getField("Amount").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            	    	cell.setBorderWidth(0);
			            	    	cell.setPaddingRight(tpPadRight);
			            	    	transTable.addCell(cell);

			            	    	//Column 5 : Total
			            	    	if(MonthlyChargesRepeatSection.getField("Total")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(MonthlyChargesRepeatSection.getField("Total").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            	    	cell.setPaddingRight(tpPadRight);
			            	    	cell.setBorderWidth(0);
			            	    	transTable.addCell(cell);
								}//end For

			            		//Add a Blank Line
			            		cell = new PdfPCell(new Phrase("",fontBold));
		    					cell.setColspan(5);
		    					cell.setBorderWidth(0);
		    					transTable.addCell(cell);
							}

							//Value Added Servcies repeat section
							if(cfiValueAddedServciesSection!=null){

								//Value Added Servcies Header
								newParagraph = new Paragraph();
					            newParagraph.add(new Phrase("Value Added Servcies", fontBold));
					            cell = new PdfPCell(newParagraph);
					            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
					            cell.setBorder(PdfPCell.BOTTOM);
					            cell.setPaddingBottom(tpPadBottom);
					            cell.setPaddingTop(tpPadTop);
					            cell.setPaddingLeft(tpPadLeft);
					            cell.setColspan(5);
					            transTable.addCell(cell);

					            //Value Added Servcies Repeat Section Part
								StatementSection ValueAddedServciesRepeatSection = null;
			           			long DetailLines = cfiValueAddedServciesSection.getSectionCount("RepeatSection");

			            		for (int i = 0; i < DetailLines; i++) {
			            		    // Get the row section
			            			ValueAddedServciesRepeatSection = cfiValueAddedServciesSection.getRepeatSection("RepeatSection", i);

			            			//Column 1 : Item
				        	        cell = new PdfPCell(new Phrase(ValueAddedServciesRepeatSection.getField("Item").asString(), font));
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
			            	    	cell.setPaddingLeft(tpPadLeft);
			            	    	cell.setBorderWidth(0);
			            	    	transTable.addCell(cell);

			            	    	//Column 2 : Date/Period
			            	    	if(ValueAddedServciesRepeatSection.getField("Date")!=null)
			            	    	{
			            	    		cell = new PdfPCell(new Phrase(ValueAddedServciesRepeatSection.getField("Date").asString(), font));
			            	    	}
			            	    	else
			            	    	{
			            	    		cell = new PdfPCell(new Phrase("", font));
			            	    	}
		 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
		 	            	    	cell.setBorderWidth(0);
		 	            	    	transTable.addCell(cell);

			            	    	//Column 3 : Rebate
		 	            	    	if(ValueAddedServciesRepeatSection.getField("Rebate")!=null)
			            	    	{
			            	    		cell = new PdfPCell(new Phrase(ValueAddedServciesRepeatSection.getField("Rebate").asString(), font));
			            	    	}
			            	    	else
			            	    	{
			            	    		cell = new PdfPCell(new Phrase("", font));
			            	    	}
		 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
		 	            	    	cell.setBorderWidth(0);
		 	            	    	cell.setPaddingRight(tpPadRight);
		 	            	    	transTable.addCell(cell);

			            	    	//Column 4 : Amount
		 	            	    	if(ValueAddedServciesRepeatSection.getField("Amount")!=null)
			            	    	{
			            	    		cell = new PdfPCell(new Phrase(ValueAddedServciesRepeatSection.getField("Amount").asString(), font));
			            	    	}
			            	    	else
			            	    	{
			            	    		cell = new PdfPCell(new Phrase("", font));
			            	    	}
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            	    	cell.setBorderWidth(0);
			            	    	cell.setPaddingRight(tpPadRight);
			            	    	transTable.addCell(cell);

			            	    	//Column 5 : Total
			            	    	if(ValueAddedServciesRepeatSection.getField("Total")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(ValueAddedServciesRepeatSection.getField("Total").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            	    	cell.setPaddingRight(tpPadRight);
			            	    	cell.setBorderWidth(0);
			            	    	transTable.addCell(cell);
								}//end For

			            		//Add a Blank Line
			            		cell = new PdfPCell(new Phrase("",fontBold));
		    					cell.setColspan(5);
		    					cell.setBorderWidth(0);
		    					transTable.addCell(cell);
							}

							//Usage Charges repeat section
							if(cfiUsageChargesSection!=null){

								//Usage Charges Header
								newParagraph = new Paragraph();
					            newParagraph.add(new Phrase("Usage Charges", fontBold));
					            cell = new PdfPCell(newParagraph);
					            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
					            cell.setBorder(PdfPCell.BOTTOM);
					            cell.setPaddingBottom(tpPadBottom);
					            cell.setPaddingTop(tpPadTop);
					            cell.setPaddingLeft(tpPadLeft);
					            cell.setColspan(5);
					            transTable.addCell(cell);

					            //Usage Charges Section Part
								StatementSection UsageChargesRepeatSection = null;
			           			long DetailLines = cfiUsageChargesSection.getSectionCount("RepeatSection");

			            		for (int i = 0; i < DetailLines; i++) {
			            		    // Get the row section
			            			UsageChargesRepeatSection = cfiUsageChargesSection.getRepeatSection("RepeatSection", i);

			            			//SubRepeatSection
				           			StatementSection SupUsageChargesRepeatSection = null;
				           			long subDetailLines = UsageChargesRepeatSection.getSectionCount("SubRepeatSection");

			            			//Column 1 : Item
				        	        cell = new PdfPCell(new Phrase(UsageChargesRepeatSection.getField("Item").asString(), font));
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
			            	    	cell.setPaddingLeft(tpPadLeft);
			            	    	cell.setBorderWidth(0);
			            	    	transTable.addCell(cell);

			            	    	//Column 2 : Date/Period
			            	    	if(UsageChargesRepeatSection.getField("Date")!=null)
			            	    	{
			            	    		cell = new PdfPCell(new Phrase(UsageChargesRepeatSection.getField("Date").asString(), font));
			            	    	}
			            	    	else
			            	    	{
			            	    		cell = new PdfPCell(new Phrase("", font));
			            	    	}
		 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
		 	            	    	cell.setBorderWidth(0);
		 	            	    	transTable.addCell(cell);

			            	    	//Column 3 : Rebate
		 	            	    	if(UsageChargesRepeatSection.getField("Rebate")!=null)
			            	    	{
			            	    		cell = new PdfPCell(new Phrase(UsageChargesRepeatSection.getField("Rebate").asString(), font));
			            	    	}
			            	    	else
			            	    	{
			            	    		cell = new PdfPCell(new Phrase("", font));
			            	    	}
		 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
		 	            	    	cell.setBorderWidth(0);
		 	            	    	cell.setPaddingRight(tpPadRight);
		 	            	    	transTable.addCell(cell);

			            	    	//Column 4 : Amount
		 	            	    	if(UsageChargesRepeatSection.getField("Amount")!=null)
			            	    	{
			            	    		cell = new PdfPCell(new Phrase(UsageChargesRepeatSection.getField("Amount").asString(), font));
			            	    	}
			            	    	else
			            	    	{
			            	    		cell = new PdfPCell(new Phrase("", font));
			            	    	}
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            	    	cell.setBorderWidth(0);
			            	    	cell.setPaddingRight(tpPadRight);
			            	    	transTable.addCell(cell);

			            	    	//Column 5 : Total
			            	    	if(UsageChargesRepeatSection.getField("Total")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(UsageChargesRepeatSection.getField("Total").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            	    	cell.setPaddingRight(tpPadRight);
			            	    	cell.setBorderWidth(0);
			            	    	transTable.addCell(cell);

			            	    	for (int l = 0; l < subDetailLines; l++) {
				            		    // Get the row section
			            	    		SupUsageChargesRepeatSection = UsageChargesRepeatSection.getRepeatSection("SubRepeatSection", l);

			            	    		//Column 1 : Item
					        	        cell = new PdfPCell(new Phrase(SupUsageChargesRepeatSection.getField("Item").asString(), font));
				            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
				            	    	cell.setPaddingLeft(tpPadLeft+tpPadLeft);
				            	    	cell.setBorderWidth(0);
				            	    	transTable.addCell(cell);

				            	    	//Column 2 : Date/Period
				            	    	cell = new PdfPCell(new Phrase("", font));
			 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
			 	            	    	cell.setBorderWidth(0);
			 	            	    	transTable.addCell(cell);

				            	    	//Column 3 : Rebate
				            	    	cell = new PdfPCell(new Phrase("", font));
			 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			 	            	    	cell.setBorderWidth(0);
			 	            	    	cell.setPaddingRight(tpPadRight);
			 	            	    	transTable.addCell(cell);

				            	    	//Column 4 : Amount
			 	            	    	if(SupUsageChargesRepeatSection.getField("Amount")!=null)
				            	    	{
				            	    		cell = new PdfPCell(new Phrase(SupUsageChargesRepeatSection.getField("Amount").asString(), font));
				            	    	}
				            	    	else
				            	    	{
				            	    		cell = new PdfPCell(new Phrase("", font));
				            	    	}
				            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            	    	cell.setBorderWidth(0);
				            	    	cell.setPaddingRight(tpPadRight);
				            	    	transTable.addCell(cell);

				            	    	//Column 5 : Total
				            	    	if(SupUsageChargesRepeatSection.getField("Total")!=null)
				            	    	{
						        	        cell = new PdfPCell(new Phrase(SupUsageChargesRepeatSection.getField("Total").asString(), font));
				            	    	}
				            	    	else
				            	    	{
						        	        cell = new PdfPCell(new Phrase("", font));
				            	    	}
				            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            	    	cell.setPaddingRight(tpPadRight);
				            	    	cell.setBorderWidth(0);
				            	    	transTable.addCell(cell);

				            	    	if(l==subDetailLines-1)
				            	    	{
				            	    		//Add a Blank Line
						            		cell = new PdfPCell(new Phrase("",fontBold));
					    					cell.setColspan(5);
					    					cell.setBorderWidth(0);
					    					transTable.addCell(cell);
				            	    	}

			            	    	}
								}//end For

			            		//Add a Blank Line
			            		cell = new PdfPCell(new Phrase("",fontBold));
		    					cell.setColspan(5);
		    					cell.setBorderWidth(0);
		    					transTable.addCell(cell);
							}

							//Discount & Rebates repeat section
							if(cfiDiscountsAndRebateSection!=null){

								//Discount & Rebates Header
								newParagraph = new Paragraph();
					            newParagraph.add(new Phrase("Discount & Rebates", fontBold));
					            cell = new PdfPCell(newParagraph);
					            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
					            cell.setBorder(PdfPCell.BOTTOM);
					            cell.setPaddingBottom(tpPadBottom);
					            cell.setPaddingTop(tpPadTop);
					            cell.setPaddingLeft(tpPadLeft);
					            cell.setColspan(5);
					            transTable.addCell(cell);

					            //Discount & Rebates Section Part
								StatementSection DiscountsAndRebateRepeatSection = null;
			           			long DetailLines = cfiDiscountsAndRebateSection.getSectionCount("RepeatSection");

			            		for (int i = 0; i < DetailLines; i++) {
			            		    // Get the row section
			            			DiscountsAndRebateRepeatSection = cfiDiscountsAndRebateSection.getRepeatSection("RepeatSection", i);

			            			//Column 1 : Item
				        	        cell = new PdfPCell(new Phrase(DiscountsAndRebateRepeatSection.getField("Item").asString(), font));
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
			            	    	cell.setPaddingLeft(tpPadLeft);
			            	    	cell.setBorderWidth(0);
			            	    	transTable.addCell(cell);

			            	    	//Column 2 : Date/Period
			            	    	if(DiscountsAndRebateRepeatSection.getField("Date")!=null)
			            	    	{
			            	    		cell = new PdfPCell(new Phrase(DiscountsAndRebateRepeatSection.getField("Date").asString(), font));
			            	    	}
			            	    	else
			            	    	{
			            	    		cell = new PdfPCell(new Phrase("", font));
			            	    	}
		 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
		 	            	    	cell.setBorderWidth(0);
		 	            	    	transTable.addCell(cell);

			            	    	//Column 3 : Rebate
			            	    	if(DiscountsAndRebateRepeatSection.getField("Rebate")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(DiscountsAndRebateRepeatSection.getField("Rebate").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
		 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
		 	            	    	cell.setBorderWidth(0);
		 	            	    	cell.setPaddingRight(tpPadRight);
		 	            	    	transTable.addCell(cell);

			            	    	//Column 4 : Amount
		 	            	    	if(DiscountsAndRebateRepeatSection.getField("Amount")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(DiscountsAndRebateRepeatSection.getField("Amount").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            	    	cell.setBorderWidth(0);
			            	    	cell.setPaddingRight(tpPadRight);
			            	    	transTable.addCell(cell);

			            	    	//Column 5 : Total
			            	    	if(DiscountsAndRebateRepeatSection.getField("Total")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(DiscountsAndRebateRepeatSection.getField("Total").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            	    	cell.setPaddingRight(tpPadRight);
			            	    	cell.setBorderWidth(0);
			            	    	transTable.addCell(cell);
								}//end For

			            		//Add a Blank Line
			            		cell = new PdfPCell(new Phrase("",fontBold));
		    					cell.setColspan(5);
		    					cell.setBorderWidth(0);
		    					transTable.addCell(cell);
							}

							//Service Tax repeat section
							if(cfiServiceTaxSection!=null){

								//Service Tax Header
								newParagraph = new Paragraph();
					            newParagraph.add(new Phrase("Service Tax (6%)", fontBold));
					            cell = new PdfPCell(newParagraph);
					            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
					            cell.setBorder(PdfPCell.BOTTOM);
					            cell.setPaddingBottom(tpPadBottom);
					            cell.setPaddingTop(tpPadTop);
					            cell.setPaddingLeft(tpPadLeft);
					            cell.setColspan(5);
					            transTable.addCell(cell);

					            //Service Tax Section Part
								StatementSection ServiceTaxRepeatSection = null;
			           			long DetailLines = cfiServiceTaxSection.getSectionCount("RepeatSection");

			            		for (int i = 0; i < DetailLines; i++) {
			            		    // Get the row section
			            			ServiceTaxRepeatSection = cfiServiceTaxSection.getRepeatSection("RepeatSection", i);

			            			//Column 1 : Item
				        	        cell = new PdfPCell(new Phrase(ServiceTaxRepeatSection.getField("Item").asString(), font));
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
			            	    	cell.setPaddingLeft(tpPadLeft);
			            	    	if(ServiceTaxRepeatSection.getField("Rebate")!=null)
			            	    	{
			            	    		cell.setColspan(2);
			            	    	}
			            	    	else
			            	    	{
			            	    		cell.setColspan(3);
			            	    	}
			            	    	cell.setBorderWidth(0);
			            	    	transTable.addCell(cell);

			            	    	//Column 2 : Rebate
			            	    	if(ServiceTaxRepeatSection.getField("Rebate")!=null)
			            	    	{
			            	    		cell = new PdfPCell(new Phrase(ServiceTaxRepeatSection.getField("Rebate").asString(), font));
			 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			 	            	    	cell.setBorderWidth(0);
			 	            	    	cell.setPaddingRight(tpPadRight);
			 	            	    	transTable.addCell(cell);
			            	    	}

			            	    	//Column 2 : Amount
			            	    	if(ServiceTaxRepeatSection.getField("Amount")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(ServiceTaxRepeatSection.getField("Amount").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            	    	cell.setBorderWidth(0);
			            	    	cell.setPaddingRight(tpPadRight);
			            	    	transTable.addCell(cell);

			            	    	//Column 3 : Total
			            	    	if(ServiceTaxRepeatSection.getField("Total")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(ServiceTaxRepeatSection.getField("Total").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            	    	cell.setPaddingRight(tpPadRight);
			            	    	cell.setBorderWidth(0);
			            	    	transTable.addCell(cell);
								}//end For

			            		//Add a Blank Line
			            		cell = new PdfPCell(new Phrase("",fontBold));
		    					cell.setColspan(5);
		    					cell.setBorderWidth(0);
		    					transTable.addCell(cell);
							}

							//Extra Section For Details of Changes Start/////////////////

							//Other Charges And Credit repeat section
							if(cfiOtherChargesAndCreditSection!=null){

								//Other Charges And Credit Header
								newParagraph = new Paragraph();
					            newParagraph.add(new Phrase("Other Charges & Credit", fontBold));
					            cell = new PdfPCell(newParagraph);
					            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
					            cell.setBorder(PdfPCell.BOTTOM);
					            cell.setPaddingBottom(tpPadBottom);
					            cell.setPaddingTop(tpPadTop);
					            cell.setPaddingLeft(tpPadLeft);
					            cell.setColspan(5);
					            transTable.addCell(cell);

					            //Other Charges And Credit Section Part
								StatementSection OtherChargesAndCreditRepeatSection = null;
			           			long DetailLines = cfiOtherChargesAndCreditSection.getSectionCount("RepeatSection");

			            		for (int i = 0; i < DetailLines; i++) {
			            		    // Get the row section
			            			OtherChargesAndCreditRepeatSection = cfiOtherChargesAndCreditSection.getRepeatSection("RepeatSection", i);

			            			//Column 1 : Item
				        	        cell = new PdfPCell(new Phrase(OtherChargesAndCreditRepeatSection.getField("Item").asString(), font));
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
			            	    	cell.setPaddingLeft(tpPadLeft);
			            	    	cell.setBorderWidth(0);
			            	    	transTable.addCell(cell);

			            	    	//Column 2 : Date/Period
			            	    	if(OtherChargesAndCreditRepeatSection.getField("Date")!=null)
			            	    	{
			            	    		cell = new PdfPCell(new Phrase(OtherChargesAndCreditRepeatSection.getField("Date").asString(), font));
			            	    	}
			            	    	else
			            	    	{
			            	    		cell = new PdfPCell(new Phrase("", font));
			            	    	}
		 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
		 	            	    	cell.setBorderWidth(0);
		 	            	    	transTable.addCell(cell);

			            	    	//Column 3 : Rebate
			            	    	if(OtherChargesAndCreditRepeatSection.getField("Rebate")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(OtherChargesAndCreditRepeatSection.getField("Rebate").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
		 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
		 	            	    	cell.setBorderWidth(0);
		 	            	    	cell.setPaddingRight(tpPadRight);
		 	            	    	transTable.addCell(cell);

			            	    	//Column 4 : Amount
		 	            	    	if(OtherChargesAndCreditRepeatSection.getField("Amount")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(OtherChargesAndCreditRepeatSection.getField("Amount").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            	    	cell.setBorderWidth(0);
			            	    	cell.setPaddingRight(tpPadRight);
			            	    	transTable.addCell(cell);

			            	    	//Column 5 : Total
			            	    	if(OtherChargesAndCreditRepeatSection.getField("Total")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(OtherChargesAndCreditRepeatSection.getField("Total").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            	    	cell.setPaddingRight(tpPadRight);
			            	    	cell.setBorderWidth(0);
			            	    	transTable.addCell(cell);
								}//end For

			            		//Add a Blank Line
			            		cell = new PdfPCell(new Phrase("",fontBold));
		    					cell.setColspan(5);
		    					cell.setBorderWidth(0);
		    					transTable.addCell(cell);
							}

							//Advantage Savings repeat section
							if(cfiAdvantageSavingsSection!=null){

								//Advantage Savings Header
								newParagraph = new Paragraph();
					            newParagraph.add(new Phrase("Advantage Savings", fontBold));
					            cell = new PdfPCell(newParagraph);
					            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
					            cell.setBorder(PdfPCell.BOTTOM);
					            cell.setPaddingBottom(tpPadBottom);
					            cell.setPaddingTop(tpPadTop);
					            cell.setPaddingLeft(tpPadLeft);
					            cell.setColspan(5);
					            transTable.addCell(cell);

					            //Advantage Savings Section Part
								StatementSection AdvantageSavingsRepeatSection = null;
			           			long DetailLines = cfiAdvantageSavingsSection.getSectionCount("RepeatSection");

			            		for (int i = 0; i < DetailLines; i++) {
			            		    // Get the row section
			            			AdvantageSavingsRepeatSection = cfiAdvantageSavingsSection.getRepeatSection("RepeatSection", i);

			            			//Column 1 : Item
				        	        cell = new PdfPCell(new Phrase(AdvantageSavingsRepeatSection.getField("Item").asString(), font));
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
			            	    	cell.setPaddingLeft(tpPadLeft);
			            	    	cell.setBorderWidth(0);
			            	    	transTable.addCell(cell);

			            	    	//Column 2 : Date/Period
			            	    	if(AdvantageSavingsRepeatSection.getField("Date")!=null)
			            	    	{
			            	    		cell = new PdfPCell(new Phrase(AdvantageSavingsRepeatSection.getField("Date").asString(), font));
			            	    	}
			            	    	else
			            	    	{
			            	    		cell = new PdfPCell(new Phrase("", font));
			            	    	}
		 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
		 	            	    	cell.setBorderWidth(0);
		 	            	    	transTable.addCell(cell);

			            	    	//Column 3 : Rebate
			            	    	if(AdvantageSavingsRepeatSection.getField("Rebate")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(AdvantageSavingsRepeatSection.getField("Rebate").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
		 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
		 	            	    	cell.setBorderWidth(0);
		 	            	    	cell.setPaddingRight(tpPadRight);
		 	            	    	transTable.addCell(cell);

			            	    	//Column 4 : Amount
		 	            	    	if(AdvantageSavingsRepeatSection.getField("Amount")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(AdvantageSavingsRepeatSection.getField("Amount").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            	    	cell.setBorderWidth(0);
			            	    	cell.setPaddingRight(tpPadRight);
			            	    	transTable.addCell(cell);

			            	    	//Column 5 : Total
			            	    	if(AdvantageSavingsRepeatSection.getField("Total")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(AdvantageSavingsRepeatSection.getField("Total").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            	    	cell.setPaddingRight(tpPadRight);
			            	    	cell.setBorderWidth(0);
			            	    	transTable.addCell(cell);
								}//end For

			            		//Add a Blank Line
			            		cell = new PdfPCell(new Phrase("",fontBold));
		    					cell.setColspan(5);
		    					cell.setBorderWidth(0);
		    					transTable.addCell(cell);
							}

							//Access Charges repeat section
							if(cfiAccessChargesSection!=null){

								//Access Charges Header
								newParagraph = new Paragraph();
					            newParagraph.add(new Phrase("Access Charges", fontBold));
					            cell = new PdfPCell(newParagraph);
					            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
					            cell.setBorder(PdfPCell.BOTTOM);
					            cell.setPaddingBottom(tpPadBottom);
					            cell.setPaddingTop(tpPadTop);
					            cell.setPaddingLeft(tpPadLeft);
					            cell.setColspan(5);
					            transTable.addCell(cell);

					            //Access Charges Section Part
								StatementSection AccessChargesRepeatSection = null;
			           			long DetailLines = cfiAccessChargesSection.getSectionCount("RepeatSection");

			            		for (int i = 0; i < DetailLines; i++) {
			            		    // Get the row section
			            			AccessChargesRepeatSection = cfiAccessChargesSection.getRepeatSection("RepeatSection", i);

			            			//Column 1 : Item
				        	        cell = new PdfPCell(new Phrase(AccessChargesRepeatSection.getField("Item").asString(), font));
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
			            	    	cell.setPaddingLeft(tpPadLeft);
			            	    	cell.setBorderWidth(0);
			            	    	transTable.addCell(cell);

			            	    	//Column 2 : Date/Period
			            	    	if(AccessChargesRepeatSection.getField("Date")!=null)
			            	    	{
			            	    		cell = new PdfPCell(new Phrase(AccessChargesRepeatSection.getField("Date").asString(), font));
			            	    	}
			            	    	else
			            	    	{
			            	    		cell = new PdfPCell(new Phrase("", font));
			            	    	}
		 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
		 	            	    	cell.setBorderWidth(0);
		 	            	    	transTable.addCell(cell);

			            	    	//Column 3 : Rebate
			            	    	if(AccessChargesRepeatSection.getField("Rebate")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(AccessChargesRepeatSection.getField("Rebate").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
		 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
		 	            	    	cell.setBorderWidth(0);
		 	            	    	cell.setPaddingRight(tpPadRight);
		 	            	    	transTable.addCell(cell);

			            	    	//Column 4 : Amount
		 	            	    	if(AccessChargesRepeatSection.getField("Amount")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(AccessChargesRepeatSection.getField("Amount").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            	    	cell.setBorderWidth(0);
			            	    	cell.setPaddingRight(tpPadRight);
			            	    	transTable.addCell(cell);

			            	    	//Column 5 : Total
			            	    	if(AccessChargesRepeatSection.getField("Total")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(AccessChargesRepeatSection.getField("Total").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            	    	cell.setPaddingRight(tpPadRight);
			            	    	cell.setBorderWidth(0);
			            	    	transTable.addCell(cell);
								}//end For

			            		//Add a Blank Line
			            		cell = new PdfPCell(new Phrase("",fontBold));
		    					cell.setColspan(5);
		    					cell.setBorderWidth(0);
		    					transTable.addCell(cell);
							}

							//Registration Chargesrepeat section
							if(cfiRegistrationChargesSection!=null){

								//Registration Charges Header
								newParagraph = new Paragraph();
					            newParagraph.add(new Phrase("Registration Charges", fontBold));
					            cell = new PdfPCell(newParagraph);
					            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
					            cell.setBorder(PdfPCell.BOTTOM);
					            cell.setPaddingBottom(tpPadBottom);
					            cell.setPaddingTop(tpPadTop);
					            cell.setPaddingLeft(tpPadLeft);
					            cell.setColspan(5);
					            transTable.addCell(cell);

					            //Registration Charges Section Part
								StatementSection RegistrationChargesRepeatSection = null;
			           			long DetailLines = cfiRegistrationChargesSection.getSectionCount("RepeatSection");

			            		for (int i = 0; i < DetailLines; i++) {
			            		    // Get the row section
			            			RegistrationChargesRepeatSection = cfiRegistrationChargesSection.getRepeatSection("RepeatSection", i);

			            			//Column 1 : Item
				        	        cell = new PdfPCell(new Phrase(RegistrationChargesRepeatSection.getField("Item").asString(), font));
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
			            	    	cell.setPaddingLeft(tpPadLeft);
			            	    	cell.setBorderWidth(0);
			            	    	transTable.addCell(cell);

			            	    	//Column 2 : Date/Period
			            	    	if(RegistrationChargesRepeatSection.getField("Date")!=null)
			            	    	{
			            	    		cell = new PdfPCell(new Phrase(RegistrationChargesRepeatSection.getField("Date").asString(), font));
			            	    	}
			            	    	else
			            	    	{
			            	    		cell = new PdfPCell(new Phrase("", font));
			            	    	}
		 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
		 	            	    	cell.setBorderWidth(0);
		 	            	    	transTable.addCell(cell);

			            	    	//Column 3 : Rebate
			            	    	if(RegistrationChargesRepeatSection.getField("Rebate")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(RegistrationChargesRepeatSection.getField("Rebate").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
		 	            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
		 	            	    	cell.setBorderWidth(0);
		 	            	    	cell.setPaddingRight(tpPadRight);
		 	            	    	transTable.addCell(cell);

			            	    	//Column 4 : Amount
		 	            	    	if(RegistrationChargesRepeatSection.getField("Amount")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(RegistrationChargesRepeatSection.getField("Amount").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            	    	cell.setBorderWidth(0);
			            	    	cell.setPaddingRight(tpPadRight);
			            	    	transTable.addCell(cell);

			            	    	//Column 5 : Total
			            	    	if(RegistrationChargesRepeatSection.getField("Total")!=null)
			            	    	{
					        	        cell = new PdfPCell(new Phrase(RegistrationChargesRepeatSection.getField("Total").asString(), font));
			            	    	}
			            	    	else
			            	    	{
					        	        cell = new PdfPCell(new Phrase("", font));
			            	    	}
			            	    	cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
			            	    	cell.setPaddingRight(tpPadRight);
			            	    	cell.setBorderWidth(0);
			            	    	transTable.addCell(cell);
								}//end For

			            		//Add a Blank Line
			            		cell = new PdfPCell(new Phrase("",fontBold));
		    					cell.setColspan(5);
		    					cell.setBorderWidth(0);
		    					transTable.addCell(cell);
							}

							//Extra Section End////////////////////////

							//Add a Blank Line and Line
		            		cell = new PdfPCell(new Phrase("",fontBold));
							cell.setColspan(5);
							cell.setPaddingLeft(tpPadLeft);
							cell.setPaddingRight(tpPadRight);
							cell.setBorderWidth(0.8f);
							cell.setBorder(PdfPCell.BOTTOM);
							transTable.addCell(cell);

							//Total Line Charges section
							if(cfiTotalLineChargesSection!=null){

								//Total Line Charges	- Item
								newParagraph = new Paragraph();
					            newParagraph.add(new Phrase("Total Line Charges", fontBold));
					            cell = new PdfPCell(newParagraph);
					            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
					            cell.setBorder(0);
					            cell.setPaddingBottom(tpPadBottom);
					            cell.setPaddingLeft(tpPadLeft);
					            cell.setColspan(4);
					            transTable.addCell(cell);

					            //Total Current Charges	- Total
					            newParagraph = new Paragraph();
					            newParagraph.add(new Phrase(cfiTotalLineChargesSection.getField("Total").asString(), fontBold));
					            cell = new PdfPCell(newParagraph);
					            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
					            cell.setBorder(0);
					            cell.setPaddingBottom(tpPadBottom);
					            cell.setPaddingRight(tpPadRight);
					            transTable.addCell(cell);
							}
							// Add 5 blank lines testing
//							for (int i = 0; i < 100; i++) {
//								cell = new PdfPCell(new Phrase("",fontBold));
//								cell.setColspan(5);
//								cell.setBorderWidth(0);
//								transTable.addCell(cell);
//							}
						}



						// add the table to the document
						document.add(transTable);

						if(DetailLines2>1 && k!=DetailLines2-1)
						{
							document.newPage();
						}
            		}
				}

            } catch (DocumentException de) {
                System.err.println(de.getMessage());
                de.printStackTrace();
            } catch (Exception ex) {
                System.err.println(ex.getMessage());
                ex.printStackTrace();
            }
        }

    public void addHeader(PdfWriter writer, Document document) {
        try {

        	//Get Image Detail from config
			com.checkfree.isolutions.property.Properties appCfg = com.checkfree.isolutions.property.PropertiesConfig.getApplicationSettings();

			if (appCfg.hasProperty("PdfPrePrintedForm") == false){
				throw new IllegalArgumentException("Image Path not specified!");
			}else{
				String ImagePath = appCfg.getProperty("PdfPrePrintedForm");

				//Add Maxis Image Background
				Image image = Image.getInstance(ImagePath);
				image.setAbsolutePosition(-40, -5.5f);
				image.scalePercent(85,85);
				image.setAlignment(Image.UNDERLYING);
				document.add(image);
			}

        } catch (Exception e) {
            throw new ExceptionConverter(e);
        }
    }

    /**
     * add the footer and header to the document when the page ended
     */
        public void onEndPage(PdfWriter writer, Document document) {

            // Draw a line at the end of the Account Summary table when the table reach end of page
            if (isAccSumm){
	            // Blank Row
	            /*for (int k=0; k < 8; k++) {
		            cell = new PdfPCell(new Phrase("", font));
		            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT + PdfPCell.ALIGN_BOTTOM);
		            summTable.addCell(cell);
	            }*/


                /*PdfContentByte cb = writer.getDirectContent();
                System.out.println("vertical pos=" + writer.getVerticalPosition(true));
                System.out.println("vertical pos1=" + writer.getVerticalPosition(false));
                cb.setLineWidth(0.5f);
                cb.moveTo(40,85);
                cb.lineTo(555,85);
                cb.stroke();*/
            }

            // Add background image
            addHeader(writer, document);
        }

        public void onStartPage(PdfWriter writer, Document document) {
            //System.out.println("Current row Count=" + rowCount);
            //System.out.println("Current page no=" +document.getPageNumber());
            rowCount=0;
            addAccSummaryHeader(writer, document);
        }

        /**
         * Add Acccount summary table header rows
         * @param writer
         * @param document
         */
        public void addAccSummaryHeader(PdfWriter writer, Document document) {

            try {
                // Add statement date and account name header (for continue of account summary table from previous page)
                if (isAccSumm){
                    //System.out.println(">>addAccSummaryHeader");
                    //Declaration
        			Phrase phrase;
        			Chunk chunk;
                    PdfPCell cell = null;
                    Paragraph newParagraph = null;

                    // padding size for the cell
        			int tpPadBottom = 5;
        			int tpPadTop = 5;
        			int tpPadRight = 5;
        			int tpPadLeft = 5;


                	Font font = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL,new Color(0, 0, 0));
    				Font fontItalic = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.ITALIC,new Color(0, 0, 0));
    				Font fontBold = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.BOLD,new Color(0, 0, 0));
    				Font fontSpace = FontFactory.getFont(FontFactory.HELVETICA, 10, Font.NORMAL,new Color(0, 0, 0));
    				Font bigFontItalic = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.ITALIC,new Color(0, 0, 0));
    				Font bigFontBold = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD,new Color(0, 0, 0));

                    // transaction detail table column widths
                    float headerwidths[] = { 7.7F, 2.3F, 4.0F, 2.0F }; // percentage
                    PdfPTable transTable = new PdfPTable(headerwidths.length);
                    transTable.setWidths(headerwidths);
                    transTable.setWidthPercentage(100); // percentage

                    // Account Summary Table

                    float summTblwidths[] = { 5.3F, 2.6F, 2.6F, 3.0F, 2.7F, 2.5F, 3.6F, 3.1F};
                    PdfPTable summaryTable = new PdfPTable(summTblwidths);
                    summaryTable.setWidthPercentage(100);



                    //Title
    				phrase = new Phrase();
    				chunk = new Chunk("ACCOUNT SUMMARY\n", bigFontBold);
    				phrase.add(chunk);
    				chunk = new Chunk("RINGKASAN AKAUN", bigFontItalic);
    				phrase.add(chunk);
                    cell = new PdfPCell(phrase);
    				cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    				cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
    				cell.setColspan(4);
    				cell.setBorderWidth(0);
    				transTable.addCell(cell);

    				//Add blank row
    				cell = new PdfPCell(new Phrase("",fontBold));
    				cell.setColspan(4);
    				cell.setBorderWidth(0);
    				transTable.addCell(cell);

    				//Statement Date
    				phrase = new Phrase();
    				chunk = new Chunk("Statement Date / ", fontBold);
    				phrase.add(chunk);
    				chunk = new Chunk("Tarikh Penyata   ", fontItalic);
    				phrase.add(chunk);
    				chunk = new Chunk(":  " + accSummStmtDate, fontBold);
    				phrase.add(chunk);
                    cell = new PdfPCell(phrase);
    				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
    				cell.setColspan(4);
    				cell.setBorderWidth(0);
    				transTable.addCell(cell);

    				for (int line=0; line < 3; line++) {
    					//Add blank row
    					cell = new PdfPCell(new Phrase("",fontBold));
    					cell.setColspan(4);
    					cell.setBorderWidth(0);
    					transTable.addCell(cell);
    				}

    				//Account Name
    				phrase = new Phrase();
    				chunk = new Chunk("Account Name / ", fontBold);
    				phrase.add(chunk);
    				chunk = new Chunk("Nama Akaun       ", fontItalic);
    				phrase.add(chunk);
    				chunk = new Chunk(":  " + accSummAccName, fontBold);
    				phrase.add(chunk);
                    cell = new PdfPCell(phrase);
    				cell.setHorizontalAlignment(Element.ALIGN_LEFT);
    				cell.setColspan(4);
    				cell.setBorderWidth(0);
    				transTable.addCell(cell);

    				// Add 10 blank lines
    				for (int i = 0; i < 10; i++) {
    					cell = new PdfPCell(new Phrase("",fontBold));
    					cell.setColspan(4);
    					cell.setBorderWidth(0);
    					transTable.addCell(cell);
    				}

    				document.add(transTable);

    				rowCount+=13;

    				// Add account summary table header only if current section is not talktime summary
    				if (!currAccSummSection.equals(ACC_SUMM_TALKTIME_SUMM)) {
	    				//// ACCOUNT SUMMARY TABLE HEADER
	    				//Header 1
	    				//Column 1 Row 1 Header 1 - Item
	    				newParagraph = new Paragraph();
	    	            newParagraph.add(new Phrase("Item", fontBold));
	    	            cell = new PdfPCell(newParagraph);
	    	            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
	    	            cell.setVerticalAlignment(PdfPCell.ALIGN_BOTTOM);
	    	            cell.setPaddingLeft(tpPadLeft);
	    	            cell.setPaddingBottom(tpPadBottom);
	    	            summaryTable.addCell(cell);

	    				//Column 2 Row 1 Header 1 - Monthly Charges
	    				newParagraph = new Paragraph();
	    	            newParagraph.add(new Phrase("Monthly\nCharges", fontBold));
	    	            cell = new PdfPCell(newParagraph);
	    	            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
	    	            cell.setVerticalAlignment(PdfPCell.ALIGN_BOTTOM);
	    	            cell.setPaddingLeft(tpPadLeft);
	    	            cell.setPaddingBottom(tpPadBottom);
	    	            summaryTable.addCell(cell);

	    				//Column 3 Row 1 Header 1 - Value Added Services
	    				newParagraph = new Paragraph();
	    	            newParagraph.add(new Phrase("Value\nAdded\nServices", fontBold));
	    	            cell = new PdfPCell(newParagraph);
	    	            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
	    	            cell.setVerticalAlignment(PdfPCell.ALIGN_BOTTOM);
	    	            cell.setPaddingLeft(tpPadLeft);
	    	            cell.setPaddingBottom(tpPadBottom);
	    	            summaryTable.addCell(cell);

	    				//Column 4 Row 1 Header 1 - Usage Charges
	    				newParagraph = new Paragraph();
	    	            newParagraph.add(new Phrase("Usage\nCharges", fontBold));
	    	            cell = new PdfPCell(newParagraph);
	    	            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
	    	            cell.setVerticalAlignment(PdfPCell.ALIGN_BOTTOM);
	    	            cell.setPaddingLeft(tpPadLeft);
	    	            cell.setPaddingBottom(tpPadBottom);
	    	            summaryTable.addCell(cell);

	    				//Column 5 Row 1 Header 1 - Other Charges
	    				newParagraph = new Paragraph();
	    	            newParagraph.add(new Phrase("Other\nCharges", fontBold));
	    	            cell = new PdfPCell(newParagraph);
	    	            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
	    	            cell.setVerticalAlignment(PdfPCell.ALIGN_BOTTOM);
	    	            cell.setPaddingLeft(tpPadLeft);
	    	            cell.setPaddingBottom(tpPadBottom);
	    	            summaryTable.addCell(cell);

	    				//Column 6 Row 1 Header 1 - Service ax
	    				newParagraph = new Paragraph();
	    	            newParagraph.add(new Phrase("Service\nTax", fontBold));
	    	            cell = new PdfPCell(newParagraph);
	    	            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
	    	            cell.setVerticalAlignment(PdfPCell.ALIGN_BOTTOM);
	    	            cell.setPaddingLeft(tpPadLeft);
	    	            cell.setPaddingBottom(tpPadBottom);
	    	            summaryTable.addCell(cell);

	    				//Column 7 Row 1 Header 1 - Discount & Rebates
	    				newParagraph = new Paragraph();
	    	            newParagraph.add(new Phrase("Discount &\nRebates", fontBold));
	    	            cell = new PdfPCell(newParagraph);
	    	            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
	    	            cell.setVerticalAlignment(PdfPCell.ALIGN_BOTTOM);
	    	            cell.setPaddingLeft(tpPadLeft);
	    	            cell.setPaddingBottom(tpPadBottom);
	    	            summaryTable.addCell(cell);

	    				//Column 8 Row 1 Header 1 - Total
	    				newParagraph = new Paragraph();
	    	            newParagraph.add(new Phrase("Total", fontBold));
	    	            cell = new PdfPCell(newParagraph);
	    	            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
	    	            cell.setVerticalAlignment(PdfPCell.ALIGN_BOTTOM);
	    	            cell.setPaddingLeft(tpPadLeft);
	    	            cell.setPaddingBottom(tpPadBottom);
	    	            summaryTable.addCell(cell);
	    	            rowCount+=3;

	    	            // Account Summary table second header
	    				if (currAccSummSection.equals(ACC_SUMM_LINE_DETAILS)) {
	    	                // Line Details Header
	    	                newParagraph = new Paragraph();
	    		            newParagraph.add(new Phrase(ACC_SUMM_LINE_DETAILS, fontBold));
	    		            cell = new PdfPCell(newParagraph);
	    		            cell.setColspan(8);
	    		            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
	    		            cell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
	    		            cell.setPaddingTop(tpPadTop);
	    		            cell.setPaddingBottom(tpPadBottom);
	    		            cell.setPaddingLeft(tpPadLeft);
	    		            summaryTable.addCell(cell);

	    	            } else if (currAccSummSection.equals(ACC_SUMM_OTHER_CHARGES)) {
			                ///////////// Other Charges Header
			                // Column 1
				            newParagraph = new Paragraph();
				            newParagraph.add(new Phrase(ACC_SUMM_OTHER_CHARGES, fontBold));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
				            cell.setPaddingLeft(tpPadLeft);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            summaryTable.addCell(cell);
				            //Column 2
			                newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("", fontBold));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setPaddingRight(tpPadRight);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            summaryTable.addCell(cell);
				            //Column 3
			                newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("", fontBold));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setPaddingRight(tpPadRight);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            summaryTable.addCell(cell);
				            //Column 4
			                newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("", fontBold));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setPaddingRight(tpPadRight);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            summaryTable.addCell(cell);
				            //Column 5
			                newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("", fontBold));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setPaddingRight(tpPadRight);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            summaryTable.addCell(cell);
				            //Column 6
			                newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("", fontBold));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setPaddingRight(tpPadRight);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            summaryTable.addCell(cell);
				            //Column 7
			                newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("", fontBold));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setPaddingRight(tpPadRight);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            summaryTable.addCell(cell);
				            //Column 8
			                newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("", fontBold));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setPaddingRight(tpPadRight);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            summaryTable.addCell(cell);

	    	            } else if (currAccSummSection.equals(ACC_SUMM_DISC_REBATES)) {
			                ///////////// Discount & Rebates Header
			                // Column 1
				            currAccSummSection = ACC_SUMM_DISC_REBATES;
				            newParagraph = new Paragraph();
				            newParagraph.add(new Phrase(ACC_SUMM_DISC_REBATES, fontBold));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
				            cell.setPaddingLeft(tpPadLeft);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            summaryTable.addCell(cell);
				            //Column 2
			                newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("", fontBold));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setPaddingRight(tpPadRight);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            summaryTable.addCell(cell);
				            //Column 3
			                newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("", fontBold));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setPaddingRight(tpPadRight);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            summaryTable.addCell(cell);
				            //Column 4
			                newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("", fontBold));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setPaddingRight(tpPadRight);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            summaryTable.addCell(cell);
				            //Column 5
			                newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("", fontBold));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setPaddingRight(tpPadRight);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            summaryTable.addCell(cell);
				            //Column 6
			                newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("", fontBold));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setPaddingRight(tpPadRight);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            summaryTable.addCell(cell);
				            //Column 7
			                newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("", fontBold));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setPaddingRight(tpPadRight);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            summaryTable.addCell(cell);
				            //Column 8
			                newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("", fontBold));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setPaddingRight(tpPadRight);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            summaryTable.addCell(cell);

	    	            } else if (currAccSummSection.equals(ACC_SUMM_SERVICE_TAX)) {
			                ///////////// Service Tax Header
			                // Column 1
				            currAccSummSection = ACC_SUMM_SERVICE_TAX;
				            newParagraph = new Paragraph();
				            newParagraph.add(new Phrase(ACC_SUMM_SERVICE_TAX, fontBold));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
				            cell.setPaddingLeft(tpPadLeft);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            summaryTable.addCell(cell);
				            //Column 2
			                newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("", fontBold));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setPaddingRight(tpPadRight);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            summaryTable.addCell(cell);
				            //Column 3
			                newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("", fontBold));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setPaddingRight(tpPadRight);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            summaryTable.addCell(cell);
				            //Column 4
			                newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("", fontBold));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setPaddingRight(tpPadRight);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            summaryTable.addCell(cell);
				            //Column 5
			                newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("", fontBold));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setPaddingRight(tpPadRight);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            summaryTable.addCell(cell);
				            //Column 6
			                newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("", fontBold));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setPaddingRight(tpPadRight);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            summaryTable.addCell(cell);
				            //Column 7
			                newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("", fontBold));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setPaddingRight(tpPadRight);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            summaryTable.addCell(cell);
				            //Column 8
			                newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("", fontBold));
				            cell = new PdfPCell(newParagraph);
				            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
				            cell.setPaddingRight(tpPadRight);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            summaryTable.addCell(cell);

	    	            }
	    	            rowCount++;
			            // Blank Row
			            for (int k=0; k < 8; k++) {
				            newParagraph = new Paragraph();
				            newParagraph.add(new Phrase("", font));
				            cell = new PdfPCell(newParagraph);
				            cell.setBorder(PdfPCell.LEFT + PdfPCell.RIGHT);
				            summaryTable.addCell(cell);
			            }
			            rowCount++;
			            document.add(summaryTable);

    				} // end if (!currAccSummSection.equals(ACC_SUMM_TALKTIME_SUMM))

                } // end if (isAccSumm)

            } catch (DocumentException de) {
                System.err.println(de.getMessage());
                de.printStackTrace();
            } catch (Exception ex) {
                System.err.println(ex.getMessage());
                ex.printStackTrace();
            }

        }


    /**
     *  Release PersistServer resource when the document close
     */
        public void onCloseDocument(PdfWriter writer, Document document) {
            //lhlue 20080427 move PersistServer to PDFDownload Servlet
            //PersistServer.commitTransaction();
            //PersistServer.deactivate();

        }

	/**
     * format the input String and replace the escape charaters
     * @param str string to format
     * @return formated String or blank String if given null String
     */

    public String formatStr (String str) {

        String strFormat=null;

		if (str == null) {

			return "";

		} else {

            strFormat = str.trim();

			// replace escape character
			strFormat = strFormat.replaceAll("&amp;", "&");
			strFormat = strFormat.replaceAll("&quot;", "\"");
			strFormat = strFormat.replaceAll("&apos;", "'");
			strFormat = strFormat.replaceAll("&lt;", "<");
			strFormat = strFormat.replaceAll("&gt;", ">");

			return strFormat;
		}
	}
    /**
     *
     * @author lhlue
     *
     * Inner class to support fields extraction of similar RepeatSection in Account Summary Table
     * (Line Details, Discount & Rebates, Service Tax )
     */
    public class SummaryRepeatSection {

        StatementSection cfiParentRepeatSection;
        long rowCount=0;

        /**
         * Constructor
         * @param parentRepeatSection Parent section of Repeat section to extract
         */
        public SummaryRepeatSection(StatementSection parentRepeatSection) throws CFiError {
            this.cfiParentRepeatSection = parentRepeatSection;
            rowCount = cfiParentRepeatSection.getSectionCount("RepeatSection");
        }
        /**
         * Get total of records count
         * @return no. of records
         */
        public long getTotalRowCount() {
            return rowCount;
        }

        /**
         * Get Item
         * @param count given record no.
         * @return String array that represent each line of items (descriptions)
         */
        public String[] getItem (int count) throws CFiError {
            StatementSection cfiRepeatSection = cfiParentRepeatSection.getRepeatSection("RepeatSection", count);
            StatementSection cfiRepeatSubSection0 = cfiRepeatSection.getRepeatSection("RepeatSubSection", 0);
            int itemCount = 0;

            if (cfiRepeatSection!=null && cfiRepeatSubSection0 !=null) {
                itemCount = (int) cfiRepeatSubSection0.getSectionCount("RepeatSubDetailsSection");
            }

            String[] desc = new String[itemCount+1];

            if (cfiRepeatSection!=null) {
                desc[0]= cfiRepeatSection.getFieldText("Item");

	            if (cfiRepeatSubSection0 !=null) {
	                for (int j=0; j < itemCount; j++) {
	                    desc[j+1] = cfiRepeatSubSection0.getRepeatSection("RepeatSubDetailsSection", j).getFieldText("Item");
	                }
	            }
            }

            return desc;
        }

        public String getMonthlyCharges(int count) throws CFiError {
            StatementSection cfiRepeatSection = cfiParentRepeatSection.getRepeatSection("RepeatSection", count);

            if (cfiRepeatSection !=null )
                return nullToEmpty(cfiRepeatSection.getFieldText("MonthlyCharges"));
            else
                return "";
        }

        //Value Added Services
        public String getVAS(int count) throws CFiError {
            StatementSection cfiRepeatSection = cfiParentRepeatSection.getRepeatSection("RepeatSection", count);
            if (cfiRepeatSection !=null )
                return nullToEmpty(cfiRepeatSection.getFieldText("VAS"));
            else
                return "";
        }

        public String getUsageCharges(int count) throws CFiError {
            StatementSection cfiRepeatSection = cfiParentRepeatSection.getRepeatSection("RepeatSection", count);
            if (cfiRepeatSection !=null )
                return nullToEmpty(cfiRepeatSection.getFieldText("UsageCharges"));
            else
                return "";
        }

        public String getOtherCharges(int count) throws CFiError {
            StatementSection cfiRepeatSection = cfiParentRepeatSection.getRepeatSection("RepeatSection", count);
            if (cfiRepeatSection !=null )
                return nullToEmpty(cfiRepeatSection.getFieldText("OtherCharges"));
            else
                return "";
        }

        public String getServiceTax(int count) throws CFiError {
            StatementSection cfiRepeatSection = cfiParentRepeatSection.getRepeatSection("RepeatSection", count);
            if (cfiRepeatSection !=null )
                return nullToEmpty(cfiRepeatSection.getFieldText("ServiceTax"));
            else
                return "";
        }

        public String getDiscountRebates(int count) throws CFiError {
            StatementSection cfiRepeatSection = cfiParentRepeatSection.getRepeatSection("RepeatSection", count);
            if (cfiRepeatSection !=null )
                return nullToEmpty(cfiRepeatSection.getFieldText("DiscountRebates"));
            else
                return "";
        }

        public String getTotal(int count) throws CFiError {
            StatementSection cfiRepeatSection = cfiParentRepeatSection.getRepeatSection("RepeatSection", count);
            if (cfiRepeatSection !=null )
                return nullToEmpty(cfiRepeatSection.getFieldText("Total"));
            else
                return "";
        }
        /**
         * if a String is null then return empty value otherwise the String value
         * @param str
         * @return
         */
        public String nullToEmpty(String str) {
            return (str==null ? "" : str.trim());
        }

    }
}
